PHP bot to get wikipedia definitions

By: Mungo Crow | 2 Years | Syntax: PHP | Views: 241
URL http://paste.itunix.eu/view/5e49390e

  1. function wikidefinition($s) {
  2.         $url = "http://it.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=1";
  3.         $ch = curl_init($url);
  4.         curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
  5.         curl_setopt($ch, CURLOPT_POST, FALSE);
  6.         curl_setopt($ch, CURLOPT_HEADER, false);
  7.         curl_setopt($ch, CURLOPT_NOBODY, FALSE);
  8.         curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
  9.         curl_setopt($ch, CURLOPT_REFERER, "");
  10.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  11.         curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
  12.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  13.         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");
  14.         $page = curl_exec($ch);
  15.         $xml = simplexml_load_string($page);
  16.         if((string)$xml->Section->Item->Description) {
  17.                 return array((string)$xml->Section->Item->Text, (string)$xml->Section->Item->Description, (string)$xml->Section->Item->Url);
  18.         } else {
  19.                 return "";
  20.         }
  21. }

Reply to "PHP bot to get wikipedia definitions"

Here you can reply to the paste above