<?php
include_once 'forecastVo.php';
include_once 'BaseVo.php';
$count=0;
$json_url = file_get_contents(
'http://maps.google.com/maps/api/geocode/json' .
'?address='jaipur'&sensor=false'); //line 9
if($json_url){
$obj = json_decode($json_url,true);
$obj2= $obj['results'];
}
?>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
解析错误:语法错误,第9行/home/a4101275/public_html/index.php中的意外T_STRING
第9行是我使用的地方file_get_contents.
错误是什么意思,我该如何解决?
您必须正确使用转义字符.您不能'在单引号封装的字符串中包含单引号().它打破了它.为了继续字符串并让PHP从字面上解释你的内部单引号,你必须逃避它\.
$json_url = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=\'jaipur\'&sensor=false');
Run Code Online (Sandbox Code Playgroud)
或者你可以使用替代字符串封装器,double-quote(").
$json_url = file_get_contents("http://maps.google.com/maps/api/geocode/json?address='jaipur'&sensor=false");
Run Code Online (Sandbox Code Playgroud)
为了将来参考,Parse error: syntax error, unexpected T_STRING通常意味着你在该行的某个地方有一个坏字符串.