There are two ways you can do it, one is using a regular expression the other is comparing strings.

First the regular expression approach:

if (preg_match("/([\<])([^\>]{1,})*([\>])/i", $string)) {
echo "string contains html";
}

And here is the other approach:

if(strlen($string) != strlen(strip_tags($string)){
echo "string contains HTML";
}

How to check whether a string contains HTML using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

− one = eight