使用curl加载头部内容

I want to load the content of head using curl only ,currently iam using

<?php 

$url="www.facebook.com";

$title='';$keywords='';$description='';
    $ch = curl_init();
$timeout=5;
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, 'http://'.$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($ch, CURLOPT_TIMEOUT,0);

    $html = curl_exec($ch);
    curl_close($ch);
echo htmlspecialchars($html);//gives the complete source.Why?

//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);

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

if($nodes->length>0)$title = $nodes->item(0)->nodeValue;

for ($i = 0; $i < $metas->length; $i++)
{
    $meta = $metas->item($i);
    if($meta->getAttribute('name') == 'description')
        $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
        $keywords = $meta->getAttribute('content');
}
echo $title. '<br/>';
echo "&nbsp;&nbsp;&nbsp;&nbsp;$description". '<br/>';
echo "&nbsp;&nbsp;&nbsp;&nbsp;$keywords";
?>

This code is returning the complete code of url but i want only of head.Don't relate it with my previous question as here it is not necessary to use curlopt_writefunction()

Despite the similarity of the names, HEADER doesn't correspond with the html <head>, nor does BODY correspond with the html <body>. CURLOPT_HEADER means include the http headers in the return value. CURLOPT_NOBODY means do not include the http payload in the return value(the payload for an http response with content-type:text/html would be the entire html document).

CURLOPT_HEADER should be TRUE, not 0

CURLOPT_NOBODY should be TRUE

curl_setopt($ch, CURLOPT_NOBODY, TRUE);