php json returning bool(false)

前端 未结 3 1121
谎友^
谎友^ 2020-12-22 01:15

Any thoughts as to why the following is not working.

$request_url = \"someurl?myId=$id\"; //returns feed like above

$json = file_get_contents($request_url,          


        
相关标签:
3条回答
  • 2020-12-22 01:46

    maybe the response's charset of $request_url is not 'utf-8' or 'ansi'.

    0 讨论(0)
  • 2020-12-22 01:49

    I replicated your problem and I observe bool(false) when the ajax url is wrong (not found). Make sure your "someurl" is valid.

    If the JSON is invalid, your script would still print it correctly. If the url returns nothing you's still observe 'string(0) ""'

    The issue is the invalid url.

    0 讨论(0)
  • 2020-12-22 01:54

    According to the PHP documentation, file_get_contents returns false on failure. This means that the url is not valid or can not be accessed from php.

    If you are trying this from a server, be sure that your firewall is not blocking this outgoing traffic.

    0 讨论(0)
提交回复
热议问题