In article <5c*************************@posting.google.com> ,
ol*@ekedahl.nu (Ola Ekedahl) wrote:
Is there a nice little function to find a string between to html-tags?
I.e. let's say I have a string with the following text:
"Hello world, <b>this is a test</b>"
I would like to cut out the text between the <b> and </b> ("this is a test").
Here are two ways, one with preg_match and one with list and split:
<?
$string = "Hello world, <b>this is a test</b>";
preg_match('/<b>.*<\/b>/i', $string, $result);
echo strip_tags($result[0]);
?>
<?
$string = "Hello world, <b>this is a test</b>";
list($junk, $good) = split('<b>', $string);
list($good, $junk) = split('</b>', $good);
echo $good;
?>
Both methods would get more complicated if the HTML gets more
complicated.
hth
--
Bulworth :
fu***@fung.arg | My email address is ROT13 encoded, decode to mail
--------------------------|--------------------------------------------------
<http://www.phplabs.com/> | PHP scripts and thousands of webmaster resources!