Re: need help with preg_match

From: Date: Sat, 08 Feb 2003 21:01:44 +0000
Subject: Re: need help with preg_match
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134895@lists.php.net to get a copy of this message
At 17:21 8-2-2003, you wrote:
Hi I have to alter this code: <?php $fp = fopen ('http://www.whatever.ee/', 'r'); for ($src = ''; !feof ($fp); $src .= fgets ($fp, 1024)); fclose ($fp); if (preg_match ('/\<font color=black\>([^<]*)\<\/font>/i', $src, $matches))
    echo    'Match: <b>'.$matches[1].'</b>';
else
    echo    'No match !';
?> It extracts the data (words) from www.whatever.com between <font=black> and </font>. It works well if the source looks something like this: <font=black>text</font> (it echos "text") but i am having some serious problems when the source looks like this<table><font=black><tr>text</tr></font></table>. It wont do anything if it is supposed to echo html. but i need html! Could somebody help me change the script so that it can extract html as well? If you can, mail me at liberache@hot.ee or just reply here.... Thank You!
anyway. this did what you asked for. <?PHP $src='<table><font color=black><tr>text</tr></font></table>.'; $pattern='/\<font color=black\>(.*)\<\/font>/i'; if (preg_match ($pattern, $src, $matches))
    echo    'Match: <b>'.htmlspecialchars($matches[0]).'</b>';
else
    echo    'No match !';
?> note that i show the output with htmlspecialchars() so you can actually see the tag while testing also note that i replaced your [^<]* with .*

« previous php.general (#134895) next »