Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- regular expression help
September 21, 2008, 11:06 am
rate this thread
I'm trying to basically remove chunks of html from a page but I must
not be doing my regular expression correctly.
What i'm trying with no avail.
$site = preg_replace("/<!DOCTYPE(.|\s)*<div class=\"notice_tan\">(.|
\s)*</div>/", "", $site);
I'm trying to remove from the very top to a specific div
Top of file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
[Multiple lines of html to]
I want to remove those lines with everything in between.
I hope this all makes sense
Re: regular expression help
Here you have a slash as part of </div>, which preg_replace() will think
is the end of the pattern. You don't have to use slashes to mark the
regex, you can use any character you want, like so:
preg_replace("^regex^", ..., ...)
This makes escaping slashes unnecessary.
You probably use (.|\s) because you don't know about the s pattern
modifier. If this modifier is set, a dot metacharacter in the pattern
matches all characters, including newlines.