Parse error: syntax error, unexpected T_STRING in php

后端 未结 3 951
南方客
南方客 2020-12-19 11:10


        
相关标签:
3条回答
  • 2020-12-19 11:46

    Why quote it at all? I can't imagine the Google API requires (or even expects) that value to be quoted.

    $json_url = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=jaipur&sensor=false'); //line 9
    

    Or, is jaipur a variable? If so:

    $json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$jaipur&sensor=false"); //line 9
    

    Hard to tell from your question what it is you're trying to accomplish...

    0 讨论(0)
  • 2020-12-19 11:49

    You have to use your escape characters correctly. You can't have a single-quote (') inside of a single-quote-encapsulated string. It breaks it. In order to continue the string and have PHP interpret your inner single-quote literally, you have to escape it with \.

    $json_url = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=\'jaipur\'&sensor=false'); 
    

    Or you can use the alternative string encapsulator, double-quote (").

    $json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address='jaipur'&sensor=false");
    

    For future reference, Parse error: syntax error, unexpected T_STRING usually means you have a bad string somewhere on that line.

    0 讨论(0)
  • 2020-12-19 11:54
    $json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address='jaipur'&sensor=false");
    

    Or escaping it with \

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