开发者

Is it possible to only allow img tags in html comment post?

开发者 https://www.devze.com 2023-01-18 07:29 出处:网络
I have a comment form on my website which, at the moment I filter out all html and turn it into plain text and also replace bad words with funny words. I want to be able to allow users to post images.

I have a comment form on my website which, at the moment I filter out all html and turn it into plain text and also replace bad words with funny words. I want to be able to allow users to post images. I couldn't see how to incorporate this to the comment page so have set it up on a separate page just dedicated to users posting images. But, I still don't want to allow any other html except img. Also, protect from sql injection.

Do开发者_开发百科es anyone have any ideas?

Thanks.


Two decent methods would be using Tidy or HTMLPurifier. Both filter HTML very well and are highly customizable to suit your needs.

With purifier (I speak from experience as I have used it) it will allow you to add something like:

img[src,alt,title] 

To the allowed tags property, which allows only those attributes in the img tag. See the website for more information / usages.


Yes, you can pass a list of allowable tags to php's strip_tags() function:

$clean_text = strip_tags($html_text, "<img>") ;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号