Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Wikipedia API

  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Wikipedia API

    At the moment, I've got this:

    PHP Code:
    <?

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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts
    It didn't work because I put http://en.wikipedia.org/ instead of http://en.wikipedia.org/wiki/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •