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

Solution:1

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;
}

Solution:2

Instead of using regex (like the other suggestions here) I use the following method:

    function isHtml($string)
    {
        if ( $string != strip_tags($string) )
        {
            return true; // Contains HTML
        }
        return false; // Does not contain HTML
    }

Here I use a PHP function strip_tags to remove any HTML from the string. It then compares the strings and if they do not match HTML tags were present.