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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:10:00+00:00 2026-06-16T05:10:00+00:00

I met a really weird problem on json_decode, with this code: $url=http://localhost:8983/solr/db/select?wt=json&rows=1&q=94305; $string=file_get_contents($url); echo

  • 0

I met a really weird problem on json_decode, with this code:

$url="http://localhost:8983/solr/db/select?wt=json&rows=1&q=94305";
$string=file_get_contents($url);
echo $string; echo '<br><br>';
$json=json_decode($string);
var_dump($json);

I got the following result:

{"responseHeader":{"status":0,"QTime":0,"params":{"q":"94305","wt":"json","rows":"1"}},"response":{"numFound":165,"start":0,"docs":[{"price":"","tags":"ATMs","phone_n":"","location":"37.42409897,-122.1709976 ","store":"Discover ATM","store_id":"478602","state":"CA","latitude":"37.42409897","address":"459 LAGUNITA","zipcode_n":"94305","longitude":"-122.1709976\r","url":"Discover_ATM_459_LAGUNITA_Stanford_CA_94305","city":"Stanford","category":"ATMs","text":["","CA","459 LAGUNITA","94305","Stanford"],"spell":["Discover ATM"]}]}}

NULL 

It seems that I cannot json_decode this string. However, when I do like this (copy the output of the string above and put it to $string directly):

$string='{"responseHeader":{"status":0,"QTime":0,"params":{"q":"94305","wt":"json","rows":"1"}},"response":{"numFound":165,"start":0,"docs":[{"price":"","tags":"ATMs","phone_n":"","location":"37.42409897,-122.1709976 ","store":"Discover ATM","store_id":"478602","state":"CA","latitude":"37.42409897","address":"459 LAGUNITA","zipcode_n":"94305","longitude":"-122.1709976\r","url":"Discover_ATM_459_LAGUNITA_Stanford_CA_94305","city":"Stanford","category":"ATMs","text":["","CA","459 LAGUNITA","94305","Stanford"],"spell":["Discover ATM"]}]}}';
$json=json_decode($string);
var_dump($json);

json_decode works. Why json_decode get NULL at the first part while works properly here?

  • 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-16T05:10:01+00:00Added an answer on June 16, 2026 at 5:10 am

    Your code looks okay, so let’s take one step closer and investigate what $output really is. It helps to choose a representation that can handle ASCII ranges that you can’t see.

    echo bin2hex($output);
    

    That will give a huge string, but you’ll be mostly interested in the front and back of the string.

    If that seems kosher, you can create an in-between representation:

    echo preg_replace('@[\x00-\x1f\x7f-\xff]@e', '" (0x" . dechex(ord("\\0")) . ") "', $output);
    

    It replaces any character in the lower or higher ASCII range with a hexadecimal representation, making it somewhat easier to spot them 🙂

    Update

    From your investigation based on the above, your string seems to contain a carriage return – \r – somewhere in the middle.

    "CA","latitude":"37.42409897","
                                ^
    

    You can remove those with a preg_replace() if it can’t be solved in another way.

    preg_replace("/\r(?!\n)/", '', $output);
    

    That removes any \r not followed by a \n.

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

Sidebar

Related Questions

Really struggling with this simple code here. I'm checking if the section with #setactionsuccess
I use sphinx + thinking_sphinx on my local machine and met really strange problem.
I met strange problem. I have never work with Devise gem before. So, i
I met a problem when Call to a member function combinestring() on a non-object.
I met a problem which is very strange, my company uses Visual Source Safe
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I met with an xml tranformation problem. After applying a suggested muenchian grouping to
Has anyone met this error? Right now i am trying to do switch from
I just met the utilities ( com.sun.awt.AWTUtilities ) to make your JFrame really transparent.
A good friend recommended this site to me, it looks really useful! I'm 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.