php - get the title of a page -
i getting title of page using following
$urlcontents = file_get_contents("$url"); preg_match("/<title>(.*)<\/title>/i", $urlcontents, $matches);
the problem having 1 of sites title on 3 lines
<head id="head"><title> title goes here </title><meta name="description" content="meta description" />
this basic onpage seo tool writing, there better way can title of page?
thank you
i found answer here
$urlcontents = file_get_contents("http://example.com/"); $dom = new domdocument(); @$dom->loadhtml($urlcontents); $title = $dom->getelementsbytagname('title'); print($title->item(0)->nodevalue . "\n"); // "example web page"
thank you
Comments
Post a Comment