note 91498 added to function.strip-tags
| From: | nauthiz693 at gmail dot com | Date: | Fri, 12 Jun 2009 20:31:46 +0000 |
| Subject: | note 91498 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156817@lists.php.net to get a copy of this message | ||
Wanted a function to do what nick's was supposed to do: "strip tags and attributes, but
with allowable attributes." but I couldn't get his to work properly, I think it had
something to do with greedy / non greedy searching. Anyway, I modified his a bit:
function strip_tags_attributes($string,$allowtags=NULL,$allowattributes=NULL){
$string = strip_tags($string,$allowtags);
if (!is_null($allowattributes)) {
if(!is_array($allowattributes))
$allowattributes = explode(",",$allowattributes);
if(is_array($allowattributes))
$allowattributes = implode(")(?<!",$allowattributes);
if (strlen($allowattributes) > 0)
$allowattributes = "(?<!".$allowattributes.")";
$string = preg_replace_callback("/<[^>]*>/i",create_function(
'$matches',
'return preg_replace("/ [^
=]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i",
"", $matches[0]);'
),$string);
}
return $string;
}
It can be used in the same way as nick's function.
----
Server IP: 209.41.74.194
Probable Submitter: 216.165.190.4
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- https://master.php.net/note/edit/91498
Del: integrated -- https://master.php.net/note/delete/91498/integrated
Del: useless -- https://master.php.net/note/delete/91498/useless
Del: bad code -- https://master.php.net/note/delete/91498/bad+code
Del: spam -- https://master.php.net/note/delete/91498/spam
Del: non-english -- https://master.php.net/note/delete/91498/non-english
Del: in docs -- https://master.php.net/note/delete/91498/in+docs
Del: other reasons-- https://master.php.net/note/delete/91498
Reject -- https://master.php.net/note/reject/91498
Search -- https://master.php.net/manage/user-notes.php