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

Strip HTML tags and it's contents too

8 August 2012, in

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 ?



Post a Comment