Support

Forums

Contact Me

PHP Code Snippet to retrieve Data from WikiPedia

This interesting code snippet is from cedTag and let you retrieve WikiPedia description using OpenSearch API. It use the Client Url Library cURL. Released under GPL v3

/**
 * @param $searchTerm
 * @param string $wikipediaServer
 * @return array|string  [text, description, url]
 */
public function getDefinitionFrom
($searchTerm, $wikipediaServer = 'http://en.wikipedia.org') { $url = $wikipediaServer.
'/w/api.php?action=opensearch&search=' .
urlencode($searchTerm) . '&format=xml&limit=1'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_REFERER, ""); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 4); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0"); $page = curl_exec($ch); $xml = simplexml_load_string($page); if ((string)$xml->Section->Item->Description) { return array((string)$xml->Section->Item->Text, (string)$xml->Section->Item->Description, (string)$xml->Section->Item->Url); } return ""; }
You might also like:
XAMPP 1.8.0 Xdebug stop working and make segmentation fault
273 days ago
XAMPP 1.8.0 Xdebug stop working and make segmentation fault
There's a new version of Xdebug released which fixes a major bug where inspecting static propertie
Install PHPUnit and PHPDocumentor in XAMPP
277 days ago
Install PHPUnit and PHPDocumentor in XAMPP
Open XAMPP Shell (start c:\xampp\xampp-control.exe and click on the button XAMPP-Shell), and run:
Eclipse PDT 2.0 is available
1601 days ago
Eclipse PDT 2.0 is available
The PDT project is working towards providing a PHP Development Environment framework. This project w
Eclipse Foundation, Zend Technologies, and IBM Announce the
2617 days ago
Eclipse Foundation, Zend Technologies, and IBM Announce the
The major news I was waiting for:Eclipse Foundation, Zend Technologies, and IBM Announce the Approva
Recommended PHP reading list
2622 days ago
Recommended PHP reading list
An impressive sum of links and good articles on PHP, worth reading!This list of recommended reading
blog comments powered by Disqus

Donations

Thank You for supporting my work