Created
November 10, 2013 09:20
-
-
Save nagarjun/7395910 to your computer and use it in GitHub Desktop.
Get the Title by passing the URL using PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the contents of Title tag from URL. | |
*/ | |
function get_title($URL) | |
{ | |
// Set the user agent so external servers don't block us. | |
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11'); | |
$page_contents = file_get_contents($URL); | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($page_contents); | |
$title = $dom->getElementsByTagName('title'); | |
return $title->item(0)->nodeValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment