From The Blog

PHP: check string has HTML tags

25 November 2012, in

you may think as the best way to check a string has HTML tags is to check the string after stripping tags:

if( strlen($string) != strlen(strip_tags($string)) ){

echo 'Contains HTML tags';

}

But, the best way is to use regular expressions:

if (preg_match("/([\<])([^\>]{1,})*([\>])/i", $string )) {
echo 'Contains HTML tags';
}



Post a Comment