api html image php

Return Google Image Search Results in HTML using PHP

I know how we can use the Google API to return image results in AJAX, but I want to be able to return images for a specific query and then output them in to HTML on my page.

For example:

Returns results with infomation and images about the top 10 results for the keyword sausages.

How can I query this url to output the images and titles of the images on my page using PHP in HTML.

I am using the following at the top of the function to return the title:

$tit = get_the_title();

Then I am apending it here:

$json = get_url_contents(''.$tit.'');

But it won’t recognize the title

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);
return $ret;
$json = get_url_contents('');
$data = json_decode($json);
foreach ($data->responseData->results as $result) {
$results[] = array('url' => $result->url, 'alt' => $result->title);


[0] => Array
[url] =>
[alt] => Sausage - Wikipedia, the free encyclopedia
[1] => Array
[url] =>
[alt] => File:Reunion sausages dsc07796.jpg - Wikimedia Commons
[2] => Array
[url] =>
[alt] => Maik's Yummy German Sausage
[3] => Array
[url] =>
[alt] => Spar's European Sausage Shop

Showing the images:

<?php foreach($results as $image): ?>
<img src="<?php echo $image["url']; ?>" alt="<?php echo $image["alt']; ?>"/><br/>
<?php endforeach; ?>

Edit after comments:

$url="" . get_the_title(); 
$json = get_url_contents($url);