EddieKidiw

Php Curl Google Trending

Apr 12th, 2017
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. function trends($url) {
  3.     $ch=curl_init();
  4.     curl_setopt($ch, CURLOPT_URL, $url);
  5.     curl_setopt($ch, CURLOPT_REFERER,"https://www.google.com");
  6.     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  7.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  8.     curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER ['HTTP_USER_AGENT']);
  9.     $result=curl_exec($ch);
  10.     return $result;
  11. }
  12. $url=trends('https://trends.google.com/trends/hottrends/atom/feed?pn=p19');
  13. $trends=new SimpleXmlElement($url);
  14. $data=$trends->channel->item;
  15. for($j=0; $j<count($data); $j++) {
  16.     if($data[$j]->title) {
  17.         echo ucwords(strtolower($data[$j]->title)) ."<br>";
  18.     }
  19. }
  20. for($i=0; $i<count($data); $i++) {
  21.     $des=explode(',', $data[$i]->description);
  22.     for($k=0; $k<count($des); $k++) {
  23.         if($des[$k]) {
  24.             echo ucwords(strtolower($des[$k])) . "<br>";
  25.         }
  26.     }
  27. }
  28. ?>
Add Comment
Please, Sign In to add comment