Archive for the ‘PHP’ Category

CakePHP is a Piece of Cake!

July 6th, 2011 1 comment

I’ve recently become aware of how behind the times my skills are , in particular if you write PHP you are expected to use a framework . I’ve chosen CakePHP and have installed it on my local Apache Server with a few permission hiccups. I’ve then completed the create a blog tutorial and it’s stunning how easy it is. It uses the MVC or Model-View-Controller system for development. To quote their documentation it CakePHP takes the monotony out of web development. We provide you with all the tools you need to get started coding what you really need to get done: the logic specific to your application. Instead of reinventing the wheel every time you sit down to a new project, check out a copy of CakePHP and get started with the real guts of your application.

Categories: Coding Tips, PHP Tags:

How to Remove Home in the Title of New Coppermine Gallery

June 30th, 2011 No comments

Edit include/

Find the function and modify as follows

function theme_page_title($section)
global $CONFIG;
$return = strip_tags(bb_decode($section)) . ' - ' . $CONFIG['gallery_name']; // original code
$return = $CONFIG['gallery_name']; // Section removed
return $return;

this change works for cpg1.5.x

Categories: Coding Tips, PHP Tags:

Parsing HTML with preg_match

April 8th, 2010 No comments

preg_match_all(‘#<b>.+?</b>#i’, $html, $matches);
// ? means non-greedy and is absolutely critical

$match[1], $match[2] contain the results

Non greedy stops the match gobbling everything between the first bold tag and the very last. I’ve never quite understood why greedy is the default behavior of RegExp (Regular Expressions) but I guess there’s a good reason for it.

PHP also has the very useful strip_tags function.

Categories: Coding Tips, PHP Tags:

Hereis Document for PHP: Great for Generation of HTML

November 19th, 2009 No comments

The great thing about hereis documents is that in most cases you don't have to backslash quotes, your "html" thus retains its visibility
echo <<<__HTML__

<li><a href=”$pressdir$file”>$file</a>

$html.= <<<__HTML__
<li><a href=”$pressdir$file”>$file</a>

return <<<__HTML__
<li><a href=”$pressdir$file”>$file</a>

it can also cope with arrays if you use the following syntax ${my_array[‘postcode’]}

return <<<__HTML__
<li><a href=”$multimap_url${my_array[‘postcode’]}”>${my_array[‘postcode’]}</a>

I see so much ugly tangled php/javascript/html/css code which could be tidied up with the PHP Hereis Document

Categories: PHP Tags:

How to Design a Database Driven PHP Page

November 11th, 2009 No comments

Design a Database Driven PHP Page

Many PHP pages turn into a mess because the PHP code is embedded into the HTML and. Over time this gets more and more tangled as the requirements change.

What is required is to make all the necessary database queries and all the manipulation of the data BEFORE you reach the first tag.

All that should appear in the HTML are the various php echos to output the dynamic parts of the page.

So here is the structure of a PHP page

query database
insert data from queries into php arrays (hashs)
General functions
Main section call functions, which manipulate the data to get that required by the dynamic web page
html section
Categories: PHP Tags: