Reputation: 198
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?
Upvotes: 0
Views: 1182
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