How to search for html TITLE tag with PHP
I know this is probably a lame post, but i’ll do it anyway.
If you want to search for HTML title, you’ll notice everyone gives out an answer like this:
$matches = array();
$pattern = ‘/<title>(.*)<\/title>/’;
preg_match($pattern, $html, $matches);$pagetitle = $matches[1];
But this actually doesn’t work in cases where there’s extra newline character. (.*) Doesn’t match new lines, which probably causes the problem. This means that it matches
<title> title </title>
but doesn’t match
<title> title
</title>
Instead, do this:
preg_match(”/<title>([^<]*)<\/title>/i”, $html_text, $title);
Recent Comments