note 117351 added to function.strip-tags
| From: | valentin dot boschatel at evalandgo dot com | Date: | Tue, 26 May 2015 09:41:59 +0000 |
| Subject: | note 117351 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202668@lists.php.net to get a copy of this message | ||
Hi,
I havee a problem with this function. I want use this symbol in my text ( < ), but it
doesn't work because I added character stuck to that symbol.
Exemple :
<?php
$test = '<p><span style="color: #ff0000; background-color:
#000000;">Complex</span> <span style="font-family:
impact,chicago;">text <50% </span> <a href="http://exempledomain.com/"><em>with</em></a>
<span style="font-size:
36pt;"><strong>tags</strong></span></p>';
echo strip_tags('$test');
// Outputs : Complex text
?>
I made a function for this :
Function:
<?php
function strip_tags_review($str, $allowable_tags = '') {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($allowable_tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
$pattern = '@<(?!(?:' . implode('|', $tags) .
')\b)(\w+)\b.*?>(.*?)</\1>@i';
}
else {
$pattern = '@<(\w+)\b.*?>(.*?)</\1>@i';
}
$str = preg_replace($pattern, '$2', $str);
return preg_match($pattern, $str) ? strip_tags_review($str, $allowable_tags) : $str;
}
echo strip_tags_review($test);
// Outputs: Complex text <50% with tags
echo strip_tags_review($test, '<a>');
// Outputs: Complex text <50% <a href="http://exempledomain.com">with</a> tags
?>
----
Server IP: 72.52.91.14
Probable Submitter: 91.213.82.241
----
Manual Page -- http://php.net/manual/en/function.strip-tags.php
Edit -- https://master.php.net/note/edit/117351
Del: integrated -- https://master.php.net/note/delete/117351/integrated
Del: useless -- https://master.php.net/note/delete/117351/useless
Del: bad code -- https://master.php.net/note/delete/117351/bad+code
Del: spam -- https://master.php.net/note/delete/117351/spam
Del: non-english -- https://master.php.net/note/delete/117351/non-english
Del: in docs -- https://master.php.net/note/delete/117351/in+docs
Del: other reasons-- https://master.php.net/note/delete/117351
Reject -- https://master.php.net/note/reject/117351
Search -- https://master.php.net/manage/user-notes.php