DEV Community

mhsohag11
mhsohag11

Posted on

Answer: Detect HTML tags in a string

If purpose is just to check if string contain html tag or not. No matter html tags are valid or not. Then you can try this.

function is_html($string) {
  // Check if string contains any html tags.
  return preg_match('/<\s?[^\>]*\/?\s?>/i', $string);
}

This works for all valid or invalid html tags…

Top comments (0)