Re: need help with preg_match

From: Date: Sat, 08 Feb 2003 22:14:59 +0000
Subject: Re: need help with preg_match
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-134902@lists.php.net to get a copy of this message
Thank You very much! It Really works the way I want it to. But i still have a slight problem. The script cant read the data if it is on several rows. For example: <table> <font color=black> <tr>text</tr> </font> </table> Is there a way to fix this problem? Thank You! "Chris Hayes" <chayes@antenna.nl> wrote in message news:5.1.1.6.0.20030208215530.01516150@pop4.antenna.nl... > 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 (#134902) next »