Webber Depor
Webber Depor

Reputation: 198

Prevent all html tags except <img>

In order to prevent XSS attacks to my site i use PHP regex like

$regex = '/[<>]/';
$preg_replace= ($regex, '', $text);

With this codes i delete < and > charaters so problem is done. However now i want that user can add <img> tag into my site while other tags like <script>must still be forbidden.How can i do that?

What i've tried

Upvotes: 0

Views: 1182

Answers (1)

Tom
Tom

Reputation: 596

You can use this:
http://htmlpurifier.org/

If that is not what you search, you can do this:
http://php.net/manual/en/function.strip-tags.php

strip_stags($string, '<img>');

Upvotes: 3

Related Questions