Welcome! » Log In » Create A New Profile

striping tags "a" with no attributes trouble

Posted by DexizeR 
DexizeR
striping tags "a" with no attributes trouble
July 09, 2009 06:08PM

Hello,

<?
require_once $script_path.&#039;htmlpurifier/library/HTMLPurifier.auto.php&#039;;


$dirty_html = &#039;<p><a href="http://flickr.com/">Julia Janen</a> bla bla bla</p>
<p><a href="http://www.flickr.com/photos/juliajanssen/720098879/" title="Streetart"><img src="http://farm2.static.flickr.com/1200/720098879_6a66809296_m.jpg" width="240" height="160" alt="Streetart" /></a></p>&#039;;


$config = HTMLPurifier_Config::createDefault();
$config->set(&#039;URI&#039;, &#039;HostBlacklist&#039;, &#039;flickr.com&#039;);
$config->set(&#039;HTML&#039;, &#039;Allowed&#039;, &#039;img[src|alt],p,a[href]&#039;);


$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
echo &#039;{&#039; . $clean_html . "}\n\n";
?>

this code successfully strips attributes contents URI defines in HostBlacklist, but it works strange - it deleted full tag "img" with attribute "src", but for tag "a" it deleted only attribute "href" and made it strange construction:

<a>Julia Janen</a>

How I can delete tags "a" with no attributes ?

P.S. Sorry for my bad English. I'm Russian.

Re: striping tags "a" with no attributes trouble
July 09, 2009 07:32PM

You probably want the patch here: http://htmlpurifier.org/phorum/read.php?5,2507 (but you'll have to adapt it to match a tags)

Sorry, you do not have permission to post/reply in this forum.