You are here: Re: Stripping HTML attributes and tags « HTML « IT news, forums, messages
Re: Stripping HTML attributes and tags

Posted by Toby Inkster on 11/29/05 00:12

JJ Harrison wrote:

> 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;

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация