Starting with PHP 5, the Tidy extension is usually available in most compiled binaries. This is not 100% effective, but can help you in this case. Tidy is trying to close all closed HTML tags in a string. With it closed, you could ignore the required tag. Then you will need to cut the end tag, which would be neat.
Typical Documentation
$str = tidy("I <3 PHP"); // second param ignores the closed tag <3> $str = strip_tags($str, '<3>') $str = str_replace('<3>', '<3', $str); echo $str;
source share