regex question
| From: | Julian Simpson | Date: | Mon, 16 Jul 2001 22:46:35 +0000 |
| Subject: | regex question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-58131@lists.php.net to get a copy of this message | ||
I'm trying to parse an existing html file using php.
I need to use regex to find the first (and only the first) occurance of <i>
and the last (and only the last) occurance of </i> in a string.
They will be replaced with ||.
example of a string:
blah blah <i>some stuff</i> that i <i>need to get</i> blah blah blah.
needs to become:
blah blah ||some stuff that i need to get|| blah blah blah.
so the following is what i need.....
//replace outer tags with ||
$string = ereg_replace ("Some regex that only finds the first
<i>","||",$string);
$string = ereg_replace ("Some regex that only finds the last
</i>","||",$string);
//take out remaining (inner) tags.
$string = ereg_replace ("<i>","",$string);
$string = ereg_replace ("</i>","",$string);
thanks
Julian