PHP Classes

edit class

Recommend this page to a friend!

      Google News  >  All threads  >  edit class  >  (Un) Subscribe thread alerts  
Subject:edit class
Summary:edit class
Messages:1
Author:mustafa hamad
Date:2011-12-21 09:36:38
 

  1. edit class   Reply   Report abuse  
Picture of mustafa hamad mustafa hamad - 2011-12-21 09:36:38
<?php
// Gogle news search api
# implemented by Amit Kumar Gaur
// Email : amitt800@gmail.com
# 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;
}
}
}
?>