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.
Coding Tips, PHP
regex
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.= <<<__HTML__
<li><a href=”$pressdir$file”>$file</a>
__HTML__;
return <<<__HTML__
<li><a href=”$pressdir$file”>$file</a>
__HTML__;
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>
__HTML__;
I see so much ugly tangled php/javascript/html/css code which could be tidied up with the PHP Hereis Document
PHP
hereis document
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
|
PHP
PHP