-
SitePoint Enthusiast
I'm not very good at these expressions.
with the following code
my $BlockTag;
$HTML_Text =qq~all
about
<SCRIPT what>
the script
</SCRIPT>
html
~;
my $BlockTag;
foreach $BlockTag ('SCRIPT', 'STYLE') {
my $NewText = '';
foreach (split(m!</$BlockTag>!i, $HTML_Text)) {
if (m!^(.*?)<$BlockTag!i) {
$NewText .= $1;
}
else {
$NewText .= $_;
}
}
$HTML_Text = $NewText;
}
print $HTML_Text
i wish to remove the lines between the <SCRIP.. till </SCRIPT> and be left with
all
about
html
but the code only works if the first word is <SCRIPT, if not it just put out silly stuff.
any ideas?
thanks
-
something like this might work. havent tested it though.
foreach $strip ('script', 'style')
{
if ($HTML =~ /<$strip/)
{
$HTML =~ s/<$strip([^$strip]*)$strip>//ig;
}
}
-
SitePoint Enthusiast
Thank you LuZer, your code is simpler and it works with the following changes:
here is the code that would work
foreach $strip ('script', 'style'){
if ($HTML_Text =~m/<$strip/i){
$HTML_Text =~s/<$strip.*$strip>\n//sig;
}
}
note the /s at the end.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks