note 82376 deleted from function.strip-tags by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 15:54:20 +0000 |
| Subject: | note 82376 deleted from function.strip-tags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154711@lists.php.net to get a copy of this message | ||
Note Submitter: Danno
----
Hi everyone,
I came across this thread looking for a way to strip out all tags but links and leaving only the
HREF attribute. I took what you guys have worked on and made it allow only the HREF attribute. This
way even if the spec changes you are sure to not let any javascript sneak in, who knows what the
future will bring :P . So I think its pretty tight, take a look at it and modify if you see any
holes.
<?php
function strip_tags_keep_links($sSource)
{
return preg_replace('/<(.*?)>/ie', "'<' .
preg_replace(array('/javascript:[^\"\']*/i',
'/\b((?![hH][rR][eE][fF]\b)\w+)[ \\t\\n]*=[
\\t\\n]*[\"\'][^\"\']*[\"\']/i', '/\s+/'),
array('', '', ' '), stripslashes('\\1')) .
'>'", strip_tags($sSource,'<a>'));
}
?>