Stripping HTML attributes and tags

J

JJ Harrison

Are there any asp scripts or programs availible that will strip
selected html tags and remove attributes (such as style info etc)
automatically availible?
 
S

Spartanicus

JJ Harrison said:
Are there any asp scripts or programs availible that will strip
selected html tags and remove attributes (such as style info etc)
automatically availible?

Any editor that supports Regexps can do that for you.
 
D

dorayme

From: JJ Harrison said:
Are there any asp scripts or programs availible that will strip
selected html tags and remove attributes (such as style info etc)
automatically availible?


I use BBEdit text editor and the grep pattern search and replace
function (or indeed often the regular search and replace), will
work for all files in any selected folder...). Powerful stuff,
handle with care.
 
J

JJ Harrison

I use BBEdit text editor and the grep pattern search and replace
function (or indeed often the regular search and replace), will
work for all files in any selected folder...). Powerful stuff,
handle with care.

I am not very confident with regular expressions, can anyone suggest a
good guide or some expressions that would remove all tags except
<p>,<br>,<ul>,<li>,<b>,<em>,<i>,<strong> and remove all remaining
attriubtes from the existing tags?

Thanks
 
J

Jim Higson

JJ said:
I am not very confident with regular expressions, can anyone suggest a
good guide or some expressions that would remove all tags except
<p>,<br>,<ul>,<li>,<b>,<em>,<i>,<strong> and remove all remaining
attriubtes from the existing tags?

I could, but this is easier:

http://uk2.php.net/strip_tags
 
T

Toby Inkster

JJ said:
I am not very confident with regular expressions, can anyone suggest a
good guide or some expressions that would remove all tags except
<p>,<br>,<ul>,<li>,<b>,<em>,<i>,<strong> and remove all remaining
attriubtes from the existing tags?

I'll bite...

#!/usr/bin/perl

$_ = <<TEST;

<p class="flibble">
This is a test. The paragraph should remain,
but the class should go, as should this
<u>underline</u>. <little>This should go too,
and not be reduced to an LI element.</little>
</p>

TEST

s/<\/(p|br|ul|li|b|em|i|strong)>/<\/\1>/ig;
s/<(p\b|br\b|ul\b|li\b|b\b|em\b|i\b|strong\b)\s*[^>]*>/<\1>/ig;
s/<\/(?!(p|br|ul|li|b|em|i|strong))[^>]*>/<\/span>/ig;
s/<(?!(\/|p\b|br\b|ul\b|li\b|b\b|em\b|i\b|strong\b))[^>]*>/<span>/ig;

print;
exit;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top