RE: [PHP] The difference between ereg and preg?

From: Date: Fri, 04 Aug 2006 12:00:28 +0000
Subject: RE: [PHP] The difference between ereg and preg?
Groups: php.general 
Request: Send a blank email to php-general+get-240103@lists.php.net to get a copy of this message
On 04 August 2006 11:30, Dave M G wrote: > Jochem, > > Thank you for responding. > > > > > does this one work?: > > preg_replace('#^<\!DOCTYPE(.*)<ul[^>]*>#is', '', > > $htmlPage); > > Yes, that works. I don't think I would have every figured > that out on my > own - it's certainly much more complicated than the ereg equivalent. > > If I may push for just one more example of how to properly > use regular > expressions with preg: > > It occurs to me that I've been assuming that with regular expressions > I could only remove or change specified text. > > What if I wanted to get rid of everything *other* than the specified > text? > > Can I form an expression that would take $htmlPage and delete > everything *except* text that is between a <li> tag and a <br> tag? That's where capturing expressions and backreferences come in handy: preg_replace ("/.*<li>(.*)<br>.*/", "$1", $htmlPage); (add qualifiers and other options to taste, as before!) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

« previous php.general (#240103) next »