note 82376 added to function.strip-tags

From: Date: Tue, 08 Apr 2008 20:20:23 +0000
Subject: note 82376 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-138030@lists.php.net to get a copy of this message
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>')); } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 67.161.27.243 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/82376 Del: integrated -- https://master.php.net/note/delete/82376/integrated Del: useless -- https://master.php.net/note/delete/82376/useless Del: bad code -- https://master.php.net/note/delete/82376/bad+code Del: spam -- https://master.php.net/note/delete/82376/spam Del: non-english -- https://master.php.net/note/delete/82376/non-english Del: in docs -- https://master.php.net/note/delete/82376/in+docs Del: other reasons-- https://master.php.net/note/delete/82376 Reject -- https://master.php.net/note/reject/82376 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138030) next »