Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - remove HTML tags from string except <img> [closed]

Tags:

html

php

I want to remove all tags except the img tag,

$words = strip_tags($words, '<img>');

Is it useful?

like image 326
manhag Avatar asked Mar 14 '26 08:03

manhag


1 Answers

Yes, to remove tags.
But strip_tags() won't help against the most dangerous thing - an XSS. You will need some regular expression, or use http://htmlpurifier.org/ to be sure there are no unwanted parameters in the <img> tag.

like image 100
Your Common Sense Avatar answered Mar 16 '26 20:03

Your Common Sense



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!