Connecting Tech Pros Worldwide Help | Site Map

Removing some HTML with preg_replace

mike
Guest
 
Posts: n/a
#1: Jul 17 '05
I need to be able to upload a file (html) to the server and strip away
everything up-to and including the <BODY> tag and everything from
</BODY> down. I have a perl script that does this successfully using
the following 2 lines...
$progress_report =~s/^.*<BODY.*?>//s;
$progress_report =~s/<\/BODY>.*//s;


I want to be able to do this with php. Can anybody help me with this?
I tried using hte regexp above in the preg_replace() function, but it
did not work.

--
Mike
knichel@cairodurham.org
John Dunlop
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Removing some HTML with preg_replace


mike wrote:
[color=blue]
> I need to be able to upload a file (html) to the server and strip away
> everything up-to and including the <BODY> tag and everything from
> </BODY> down.[/color]

For that one needs a parser, not a single regular expression.

--
Jock
Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Removing some HTML with preg_replace


"mike" <knichel@cairodurham.org> wrote in message
news:d5b2d8a3.0404230656.74fd69ae@posting.google.c om...[color=blue]
> I need to be able to upload a file (html) to the server and strip away
> everything up-to and including the <BODY> tag and everything from
> </BODY> down. I have a perl script that does this successfully using
> the following 2 lines...
> $progress_report =~s/^.*<BODY.*?>//s;
> $progress_report =~s/<\/BODY>.*//s;
>[/color]

The same regexps, different syntax:

$progress_report = preg_replace(array('/^.*<BODY.*?>/si', '/<\/BODY>.*/si'),
array('', ''), $progress_report);


Closed Thread