note 71370 deleted from function.strip-tags by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 15:58:19 +0000 |
| Subject: | note 71370 deleted from function.strip-tags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154726@lists.php.net to get a copy of this message | ||
Note Submitter: bermi ferrer at (google it yourself :P )
----
This is Salaverts function improved with suggestions from this page as it has been refactored forthe
Akelos Framework (http://www.akelos.org) by Jose Salavert
Please note that the "u" modifier need to be lowercased. This function will also replace
self-closing tags (XHTML <br /> <hr />) and will work if the text contains line breaks.
<?php
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.'[^>]*>((\\n|\\r|.)*)<\/'. $tag
.'>/iu', $text, $found)){
$text = str_replace($found[0],$found[1],$text);
}
}
return
preg_replace('/(<('.join('|',$tags).')(\\n|\\r|.)*\/>)/iu',
'', $text);
}
?>