Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if string contents have any HTML in it?

How can I check if PHP string contents contain any HTML contents?

I'm not good with Regular Expressions so I would like to have a function named "is_html" to check this. :) thank you!


1 Answers

If you want to test if a string contains a "<something>", (which is lazy but can work for you), you can try something like that :

function is_html($string)
{
  return preg_match("/<[^<]+>/",$string,$m) != 0;
}
like image 107
nico Avatar answered Sep 14 '25 06:09

nico