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

get title of website via link

$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

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -