Title, meta description & keywords of a webpage using curl

CURL should be enabled for php. You can check it in php.ini. Here is the php code to fetch title, meta keywords & meta description of a webpage by providing its url.

$url = "http://amandip.net/php-mysql/get-emails-from-inbox-of-email-server";
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$html = curl_exec($ch);
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
curl_close($ch);

if(!empty($errmsg)){
exit($errmsg);
}

//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;

$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if(strtolower($meta->getAttribute('name')) == 'description')
$description = $meta->getAttribute('content');
if(strtolower($meta->getAttribute('name')) == 'keywords')
$keywords = $meta->getAttribute('content');
}
}
catch(Exception $e){
exit($e->getMessage());
}