Re: regex question

From: Date: Mon, 16 Jul 2001 23:16:09 +0000
Subject: Re: regex question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-58141@lists.php.net to get a copy of this message
You could do it using the strpos() function to find the index of the first occurance of "<i>" and strrpos() for the last occurence. Then use substr() to grab what you want... On Mon, 16 Jul 2001, Julian Simpson wrote: > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#58141) next »