Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 491787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:02:48+00:00 2026-05-13T02:02:48+00:00

I noticed there was a question somewhat similar to mine, only with c#: link

  • 0

I noticed there was a question somewhat similar to mine, only with c#:link text.
Let me explain: I’m very new to the whole web-services implementation and so I’m experiencing some difficulty understanding (especially due to the vague MediaWiki API manual).

I want to retrieve the entire page as a string in PHP (XML file) and then process it in PHP (I’m pretty sure there are other more sophisticated ways to parse XML files but whatever):
Main Page wikipedia.

I tried doing $fp = fopen($url,'r');. It outputs: HTTP request failed! HTTP/1.0 400 Bad Request. The API does not require a key to connect to it.

Can you describe in detail how to connect to the API and get the page as a string?

EDIT:
The URL is $url='http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main Page';. I simply want to read the entire content of the file into a string to use it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T02:02:49+00:00Added an answer on May 13, 2026 at 2:02 am

    Connecting to that API is as simple as retrieving the file,

    fopen

    $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
    $fp = fopen($url, 'r');
    while (!feof($fp)) {
        $c .= fread($fp, 8192);
    }
    echo $c;
    

    file_get_contents

    $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
    $c = file_get_contents($url);
    echo $c;
    

    The above two can only be used if your server has the fopen wrappers enabled.

    Otherwise if your server has cURL installed you can use that,

    $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $c = curl_exec($ch);
    echo $c;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very beginner's question: I noticed that there's no .to_d (such as order.price.to_d to convert
I've noticed that there are a couple of similar questions and answers at SO
So I'm somewhat new to programming and mostly self-taught, so sorry if this question
I'm very new to Padrino (I come from a PHP background), and ruby web
I noticed there's not question with a list of common causes of segmentation faults
I've noticed that there are several question on this exception. But they do not
Edit: There is a somewhat strange solution to this question. Check my answer posted
First, I noticed there are many questions regarding this, lots marked as duplicate. I
I've noticed there are a few solutions to allow the use of memcached on
I just noticed there is no * in front of the declaration for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.