If I use your code, I get a Fatal error: Cannot redeclare strip_tags().
Changing the name function to something like my_strip_tags works fine.
function my_strip_tags($text, $tags = '', $invert = FALSE) {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
}
}
elseif($invert == FALSE) {
return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
}
return $text;
}
$html_source_code = "Beginning of content ... <a href='http://test.blogspot.com/2012/11/myblog.html'>London</a> ... end of content.";
echo "<p>".$html_source_code."</p>";
$string = my_strip_tags($html_source_code, '<a>', TRUE);
echo "<p>".$string."</p>";
That prints:
Beginning of content ... London... end of content.
Beginning of content ... ... end of content.