So I have the following PHP script which works well.
I'm a newbie here, but trying to create a workflow where I can enter an argument, and it pings google, and returns the top result URL to me, copied to my clipboard.
Like I said, on the last line, I do successfully return the top result, but not entirely sure how to hook up the rest of the workflow.
Here you can see the workflow at the moment -> https://www.dropbox.com/s/pfo7b0uap41bd0g/Screenshot%202014-08-05%2016.13.02.png
Any help would be much appreciated!
function get_url_contents($url) {
$crl = curl_init();
curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
$q = $argv[1]; //Get user-inputted argument
$json = get_url_contents('http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=.$q.');
$data = json_decode($json);
foreach ($data->responseData->results as $result) {
$results[] = array('url' => $result->url, 'alt' => $result->title);
}
$url = $results[0]['url'];
echo $url;