-3

I want to do a simple kind of test to see if a string contains any HTML.

In this case if the $string variable is test or <test> it returns no for me:

$string = 'test';
if(strpos($string,'<') !== 'false'){
    echo 'no';
}else{
    echo 'yes';
}

Is there a better way to check if a string contains HTML? I don't want to do anything to the string just check if it has HTML tags?

Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76

1 Answers1

-2
if($string != strip_tags($string)) {
    // contains HTML
}

Took the answer from here

CHE6yp
  • 86
  • 7