Skip to content

Instantly share code, notes, and snippets.

@titomus
Created August 10, 2017 07:17
Embed
What would you like to do?
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