On 04 August 2006 10:52, Dave M G wrote:
> Chris, Ligaya, Dave,
>
> Thank you for responding. I understand the difference in principle
> between ereg and preg much better now.
>
> Chris wrote:
> > ! in perl regular expressions means "not" so you need to escape it:
> > \!
AFAIR, that's only true in the (?! assertion sequence.
> Still, when including that escape character, the following preg
> expression does not find any matching text:
> preg_replace("/<\!DOCTYPE(.*)<ul>/", "", $htmlPage);
>
> Whereas this ereg expression does find a match:
> ereg_replace("<!DOCTYPE(.*)<ul>", "", $htmlPage);
>
> What do I need to do to make the preg expression succeed just as the
> ereg expression does?
By default, . in preg_* patterns does not match newlines. If you are matching
in a multiline string, use the s modifier to change this:
preg_replace("/<!DOCTYPE(.*)<ul>/s", "", $htmlPage);
You also don't need the parentheses -- these will capture the entire matched
expression for use in backreferences, but as you don't have any it's then
immediately thrown away. So just use:
preg_replace("/<!DOCTYPE.*<ul>/s", "", $htmlPage);
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: [EMAIL PROTECTED]
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