Hamza Zafeer Hamza Zafeer - 6 months ago 12
PHP Question

Check If There is HTML in input

I have a textarea where user can add something. To avoid inserting HTML i use following

PHP functions
on textarea?

$text = addslashes(strip_tags(htmlspecialchars($_POST['message'])));


A message from the user is looks like in the DB like below.

8KsAtP <a href="http://lqexajgwyrsk.com/">lqexajgwyrsk</a>,
[url=http://imndawriqhnk.com/]imndawriqhnk[/url],
[link=http://qyozfozrqier.com/]qyozfozrqier[/link],
http://oykrvybeqata.com/


My Question is that how can i check there is HTML code in textarea, instead of inserting it in DB like above i want to show error message.

Answer

To answer your question directly:

// check there is no html content
if(strip_tags($_POST['message']) == $_POST['message']) {
    // continue to process
} else {
    // there is html in the message
}
Comments