Skip to content

Instantly share code, notes, and snippets.

@titomus
Created August 10, 2017 07:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titomus/a219b0d7519c2f704a210b012e925716 to your computer and use it in GitHub Desktop.
Save titomus/a219b0d7519c2f704a210b012e925716 to your computer and use it in GitHub Desktop.
Function pour récupérer le nombre de résultats Google (FR)
<?php
function get_search_num($keyword){
$url = sprintf('http://www.google.fr/search?pws=0&hl=fr&q=%s', $keyword);
$data = file_get_contents($url);
$pattern = sprintf(
'/%s(.*?)%s/',
preg_quote('Environ'),
preg_quote('résultats')
);
preg_match_all($pattern, utf8_encode($data), $matches);
return trim($matches[1][0]);
}
// utilisation
echo get_search_num('seo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment