<?php
$ch = curl_init('https://www.facebook.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/*
* XXX: This is not a "fix" for your problem, this is a work-around. You
* should fix your local CAs
*/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/* Set a browser UA so that we aren't told to update */
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36');
$res = curl_exec($ch);
if ($res === false) {
die('error: ' . curl_error($ch));
}
curl_close($ch);
$d = new DOMDocument();
@$d->loadHTML($res);
$output = array(
'title' => '',
'meta' => ''
);
$x = new DOMXPath($d);
$title = $x->query("//title");
if ($title->length > 0) {
$output['title'] = $title->item(0)->textContent;
}
$meta = $x->query("//meta[@name = 'description']");
if ($meta->length > 0) {
$output['meta'] = $meta->item(0)->getAttribute('content');
}
print_r($output);
?>
This displays:
Array ( [title] => Welcome to Facebook - Log In, Sign Up or Learn More [meta] => Facebook is a social utility that connects people with friends and others who work, study and live around them. People use Facebook to keep up with friends, upload an unlimited number of photos, post links and videos, and learn more about the people they meet. )