Hamza Zafeer Hamza Zafeer - 1 year ago 56
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>,

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 Source

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