I recently discovered the strip_tags() function which takes a string and a list of accepted html tags as parameters.
Lets say I wanted to get rid of images in a string here is an example:
$html = '<img src="example.png">';
$html = '<p><strong>This should be bold</strong></p>';
$html .= '<p>This is awesome</p>';
$html .= '<strong>This should be bold</strong>';
echo strip_tags($html,"<p>");
returns this:
<p>This should be bold</p>
<p>This is awesome</p>
This should be bold
consequently I gotten rid of my formatting via <strong> and perhaps <em> in the future.
I want a way to blacklist rather than whitelist something like:
echo blacklist_tags($html,"<img>");
returning:
<p><strong>This should be bold<strong></p>
<p>This is awesome</p>
<strong>This should be bold<strong>
Is there any way to do this?
If you only wish to remove the
<img>tags, you can useDOMDocumentinstead ofstrip_tags().