RE: The difference between ereg and preg?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux