...

View Full Version : Wikipedia API



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


<?

$url = "http://en.wikipedia.org/w/api.php?"
."action=query&"
."list=exturlusage&"
."format=xml&"
."euquery=www.fender.com";

// 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?

Fou-Lu
11-04-2009, 10: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).

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum