Last active
July 8, 2021 15:44
-
-
Save joshlewis/7882722 to your computer and use it in GitHub Desktop.
A fun little toy written in PHP that will show you google suggest results for any given phrase.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
A script to display the top ten Google suggestions for any given string | |
First version by Josh Lewis https://github.com/joshlewis | |
Original script at https://gist.github.com/joshlewis/7882722 | |
*/ | |
if ($argc > 1) { | |
array_shift($argv); | |
} else { | |
echo "Usage: php ".preg_replace('/'.preg_quote(dirname(__FILE__).'/', '/').'/', '', __FILE__)." \"your phrase goes here\"\n"; | |
exit; | |
} | |
$rawSearch = implode(' ',$argv); | |
$queryString = urlencode($rawSearch); | |
$finalUrl = 'http://google.com/complete/search?output=toolbar&q='.$queryString; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $finalUrl); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$sugg = new SimpleXMLElement(curl_exec($ch)); | |
echo "Google's suggestions for \"".$rawSearch."\":\n\n"; | |
foreach ($sugg->CompleteSuggestion as $item) { | |
//echo preg_replace('/'.$rawSearch.'/', '...', $item->suggestion['data'])."\n"; //Half-hearted attempt to remove the entered text | |
echo $item->suggestion['data']."\n"; //Just show the raw suggestions unaltered | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of today, this is still working. 👍