I'm using PHP's strip_tags()
function to strip tags from a string. For example:
$text = strip_tags( $text );
My aim is to strip all tags unless the tags happen to be contained inside backticks. If tags are contained inside backticks, I don't want to strip them.
My first thought was to try using the second parameter of strip_tags()
. This will let me specify allowable tags which are not to be removed. For example, strip_tags( $text, '<strong>')
. However, this doesn't quite do what I'm looking for.
How can I strip all HTML tags from a string except tags that happen to be contained inside backticks?