note 61834 added to function.strip-tags
| From: | salavertat~akelos at osu1 dot php dot net | Date: | Mon, 13 Feb 2006 10:21:13 +0000 |
| Subject: | note 61834 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103619@lists.php.net to get a copy of this message | ||
<?php
/**
* Works like PHP function strip_tags, but it only removes selected tags.
* Example:
* strip_selected_tags('<b>Person:</b>
<strong>Salavert</strong>', 'strong') => <b>Person:</b>
Salavert
*/
function strip_selected_tags($text, $tags = array())
{
$args = func_get_args();
$text = array_shift($args);
$tags = func_num_args() > 2 ? array_diff($args,array($text)) : (array)$tags;
foreach ($tags as $tag){
if(preg_match_all('/<'.$tag.'[^>]*>(.*)<\/'.$tag.'>/iU',
$text, $found)){
$text = str_replace($found[0],$found[1],$text);
}
}
return $text;
}
?>
Hope you find it useful,
Jose Salavert
----
Server IP: 130.206.1.5
Probable Submitter: 83.37.219.103
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61834
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61834&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61834&report=yes
Search -- http://master.php.net/manage/user-notes.php