I think the strip_tags () function matches its name. All this is a matter of perspective. :-) Without the second parameter, it breaks all the tags. The second parameter provides exceptions for the main functions.
It seems that you want strip_some_tags()
.
How to do this with regex?
function strip_some_tags($input, $taglist) { $output=$input; foreach ($taglist as $thistag) { if (preg_match('/^[az]+$/i', $thistag)) { $patterns=array( '/' . "<".$thistag."\/?>" . '/', '/' . "<\/".$thistag.">" . '/' ); } else if (preg_match('/^<[az]+>$/i', $thistag)) { $patterns=array( '/' . str_replace('>', "?>", $thistag) . '/', '/' . str_replace('<', "<\/?", $thistag) . '/' ); } else { $patterns=array(); } $output=preg_replace($patterns, "", $output); } return $output; } $to_strip=array( "iframe", "script", "style", "embed", "object" ); $sampletext="Testing. <object>Am I an object?</object>\n"; print strip_some_tags($sampletext, $to_strip);
Return:
Testing. Am I an object?
Of course, this just separates the tags, not the things between them. Is this what you want? You did not indicate in your question.
ghoti source share