array(
'method'=>"GET",
'header'=>"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n".
"Accept-language: en-US,en;q=0.8\r\n".
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36\r\n".
"Upgrade-Insecure-Requests: 1\r\n"
)
);
$context = stream_context_create($opts);
// $response = file_get_contents($url, false, $context);
try {
$response = file_get_contents($url, false, $context);
if ($response === false) {
$response = "Error!
";
}
} catch (Exception $e) {
$response = "Exception!
";
}
return $response;
}
/* Parser:
Parse and generate citation info (the number and the list of citations)
from a Google search page with a paper title as keywords:
e.g., $url = 'https://www.google.com/search?q=collecting+telemetry+data+privately'
*/
function get_cites($url) {
$page = get_url_response($url);
$ind_citenum = strpos($page, '>Cited by ');
if ($ind_citenum === false) {
return '';
}
$ind_citenum_end = strpos($page, '<', $ind_citenum);
$cite_text = substr($page, $ind_citenum + 10, $ind_citenum_end - $ind_citenum - 10);
$page_left = substr($page, 0, $ind_citenum);
$ind_cites = strrpos($page_left, 'cites=');
$ind_cites_end = strpos($page_left, '"', $ind_cites);
$cite_link = substr($page_left, $ind_cites, $ind_cites_end - $ind_cites);
$cite_link = 'http://scholar.google.com/scholar?'.$cite_link;
return ' cited by '.$cite_text.'';
}
if (!isset($_GET["q"]))
exit -1;
echo get_cites($url0.urlencode($_GET["q"]));
?>