/ Published in: PHP
If you need to add some content to your pages without having that content in your database you can use Wikipedia API. You can, for example, need to add automatically a simple description to a city name, or to a band name. Or you could need to add the definition of some technological terms. You can do all of this things using Wikipedia, since Wikipedia has an API that easily lets you do it.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function wikidefinition($s) { $url = "http://it.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=1"; 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"); if((string)$xml->Section->Item->Description) { return array((string)$xml->Section->Item->Text, (string)$xml->Section->Item->Description, (string)$xml->Section->Item->Url); } else { return ""; } }
URL: http://www.barattalo.it/2010/08/29/php-bot-to-get-wikipedia-definitions/