public function getShares($url)
{
$html = file_get_contents(sprintf(self::IFRAME_URL, urlencode($url)));
// Disable libxml errors
$internalErrors = libxml_use_internal_errors(true);
$document = new \DOMDocument();
$document->loadHTML($html);
$aggregateCount = $document->getElementById('aggregateCount');
// Restore libxml errors
libxml_use_internal_errors($internalErrors);
// Instead of big numbers, Google returns strings like >10K or 12M
if (preg_match('/([0-9]+)(K|M)/', $aggregateCount->nodeValue, $matches)) {
$multiplier = 'K' === $matches[2] ? 1000 : 1000000;
return $matches[1] * $multiplier;
}
return intval($aggregateCount->nodeValue);
}