View Full Version : Wikipedia API

11-04-2009, 11:16 PM
At the moment, I've got this:


$url = "http://en.wikipedia.org/w/api.php?"

// Get raw data
$response = file_get_contents($url);

// Convert raw data to object
$xml = simplexml_load_string($response);

// Loop through data and display
foreach($xml->query->exturlusage->eu as $link)
echo "<H1><A href=\"http://en.wikipedia.org/{$link['title']}\">{$link['title']}</H1></A>";


It's showing all wikipedia pages that link to www.fender.com. I want each to link to their wikipedia pages, I've done the best I can but {[$link['title']} inserts the title with spaces, and I need them to be %20 to work. Anyone know a way to do it, or any other ways of linking them?

11-04-2009, 11:22 PM
You want to use urlencode($link['title']) in order to convert spaces and other special characters to a url passable string.
I'd actually look into the $link array first, there may be a url option in it (assuming that they forsaw this as a possibility).

11-05-2009, 03:15 PM
It didn't work because I put http://en.wikipedia.org/ instead of http://en.wikipedia.org/wiki/