regex makes my head hurt
| From: | Kris Jones | Date: | Tue, 04 Mar 2003 17:55:54 +0000 |
| Subject: | regex makes my head hurt | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-138143@lists.php.net to get a copy of this message | ||
I've been attempting to figure out regex, and I've realized I need to start over from scratch. And get lots of help!
I'm inputting a text file containing html which will contain this:
<a href="/q?s=IBM&d=t">IBM</a></font></td><td nowrap align=center>
<font face=arial size=-1>2:59pm</font></td>
<td nowrap><font face=arial size=-1>
<b>76.17</b></font></td><td nowrap>
I need to be able to match this string via a variable. I would like to put everything from the "<a href>" to the "<td nowrap>" into a variable so I can parse it later. I think I can do that bit on my own.
So I "borrowed" some code from another source, but I need an algorithm that will match the above chunk of html.
I give it the name:
$name = "IBM";
and it matches everything from the "<a href>" to the "<td nowrap>".
if (preg_match("/ <a href> part using $name(.*?)<td nowrap>/", $line, $out)) {
$title = $out[1];
break;
}
}
echo "$title";
I can't figure out how to escape all the parts of:
<a href="/q?s=$name&d=t">
Do the other parts look okay?
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail