PHP: check string has HTML tags


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'; }

Strip HTML tags and it’s contents too


To strip tags we can use the php function strip_tags($str) but it will return the content of the tags too, How to strip html tags and remove it's contents too ? /** * Remove HTML tags, including invisible text such as style and * script code, and embedded objects. Add line breaks around * block-level … Continue reading Strip HTML tags and it’s contents too