Advertisement
abhijit5893

wikisrch

Dec 15th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. <?php
  2. $q=$_GET['message'];
  3. $url = "http://en.wikipedia.org/w/api.php?format=xml&action=opensearch&search=".$q."&limit=5&namespace=0";
  4. trim($url);
  5. $ch = curl_init();
  6.     curl_setopt($ch,CURLOPT_URL,$url);
  7.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  8.     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
  9.     $page = curl_exec($ch);
  10.     $xml = new SimpleXMLElement($page);
  11.  
  12.     foreach($xml->Section->Item as $it){
  13.     echo "<a href='".$it->Url."'>".$it->Text."</a><br/>";
  14.     }
  15.  
  16. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement