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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay