<?php 
// Gogle news search api 
# implemented by Amit Kumar Gaur 
// Email : 
[email protected] 
# blog: http://amitkgaur.blogspot.com 
class GoogleNews { 
    public $ans; 
    public function __construct($ww) { 
        $url = "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=".$ww; 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, $url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_REFERER, "http://amitkgaur.blogspot.com"); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
        $this->ans= curl_exec($ch); 
        curl_close($ch); 
    } 
} 
$searchWord="mustafa hamad"; 
$qq=urlencode($searchWord); 
$gn=new GoogleNews($qq); 
$outPut = json_decode($gn->ans); 
foreach($outPut->responseData->results as $p) { 
echo "<hr>"; 
    echo "<br>".$p->GsearchResultClass; 
    echo "<br>".$p->clusterUrl; 
    echo "<br>".$p->content; 
    echo "<br>".$p->unescapedUrl; 
    echo "<br>".$p->url; 
    echo "<br>".$p->image->url; 
    echo "<br>".$p->image->tbUrl; 
    echo "<br>".$p->image->originalContextUrl; 
     
} 
echo "<hr>"; 
foreach($outPut->responseData->results as $r) { 
	if(!empty($r->relatedStories)){
		foreach($r->relatedStories as $rr){ 
			echo "<br>".$rr->unescapedUrl; 
			echo "<br>".$rr->url; 
		} 
	}
} 
?>