regular expression help

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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]

<div class="notice_tan">
    [more html]

I want to remove those lines with everything in between.
I hope this all makes sense

Re: regular expression help

Rene wrote:
Quoted text here. Click to load it

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.

Re: regular expression help

ok so remove the beginning and ending slashes and how do I hangle the
</div> so it doesn't think it's the end of the expression?

Re: regular expression help

Lars Eighner wrote:
Quoted text here. Click to load it

What are?

Re: regular expression help


Quoted text here. Click to load it



Site Timeline