/* Locate where <title> is located in html file. */
$lBound = strpos($msg, '<title>') + 7; //7 is the lengh of <title>.
if ($lBound < 1)
return;
/* Locate where </TITLE> is located in html file. */
$uBound = strpos($msg, '</title>', $lBound);
if ($uBound < $lBound)
return;
/* Clean HTML and PHP tags out of $title with the madness below. */
$title = ereg_replace("[\t\n\r]", '', substr($msg, $lBound, $uBound - $lBound));
$title = trim(strip_tags($title));
if (strlen($title) < 1) //A blank title is worthless.
return;