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 8168183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:26:10+00:00 2026-06-06T20:26:10+00:00

I have the following URL: https://api.stackexchange.com/2.0/questions?page=1&pagesize=30&order=desc&sort=activity&site=stackoverflow When I type this URL in my browser’s

  • 0

I have the following URL:

https://api.stackexchange.com/2.0/questions?page=1&pagesize=30&order=desc&sort=activity&site=stackoverflow

When I type this URL in my browser’s address bar, it gives me a JSON response, which I need in PHP. I tried using cURL to fetch it (see below code), but it didn’t work — no response is printed on the page.

function get_json($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);

    $data = curl_exec($ch);
    $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($resultCode == 200) {
        return json_decode($data);
    } else {
        return false;
    }
}

$json = get_json('https://api.stackexchange.com/2.0/questions?page=1&pagesize=30&
  key=VVq3kJHSjQ*7qgpiRaVoLA%28%28&site=stackoverflow');
echo '<pre>';
print_r($json);

How can I fetch this URL and convert it into a PHP array the right way?

  • 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-06-06T20:26:13+00:00Added an answer on June 6, 2026 at 8:26 pm

    Last I checked, all responses from the API were gzip’d:

    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url
      , CURLOPT_HEADER => 0
      , CURLOPT_RETURNTRANSFER => 1
      , CURLOPT_ENCODING => 'gzip'
    ));
    $data = curl_exec($ch);
    var_dump($data);
    var_dump(json_decode($data));
    

    Setting CURLOPT_ENCODING enables automatic un gzip’ing of the response, in addition to sending an Accept-Encoding: gzip in the http request, although sending that header isn’t strictly required for this to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following restful api ajax call: $.ajax({ type: POST, url: https://website.com/a/login, data:
I have a URL which can be any of the following formats: http://example.com https://example.com
I'm playing with YouTube API. Using the following URL: https://gdata.youtube.com/feeds/api/users/RayWilliamJohnson/uploads , how do I
All, I have the following code: $c = curl_init(); curl_setopt($c, CURLOPT_URL, https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_many}); curl_setopt($c, CURLOPT_RETURNTRANSFER,
I have written down the following code: var url = http://maps.googleapis.com/maps/api/geocode/json?latlng=+position.coords.latitude+,+position.coords.longitude+&sensor=false&callback=parseMe; console.log('URL is --
So I have the following code: NSURL *baseURL = [NSURL URLWithString:@http://www.baseurltoanxmlpage.com]; NSURL *url =
I have the following code in my .Zshrc function google; { $VIEW http://www.google.com/search?q='url-encode ${(j:
I use the following command in some old scripts: curl -Lk https:www.example.com/stuff/api.php? I then
I have the following code $curl_handle = curl_init(); $api_url = 'http://api.twitter.com/1/statuses/home_timeline.json'; curl_setopt($curl_handle, CURLOPT_URL, $api_url);
I'm trying to do the following Facebook Query Language query: https://api.facebook.com/method/fql.query?query=SELECT name FROM user

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.