解析错误:语法错误,PHP中出现意外的T_STRING [英] Parse error: syntax error, unexpected T_STRING in php

查看:299
本文介绍了解析错误:语法错误,PHP中出现意外的T_STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?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'];
    }
?>

我遇到错误:

解析错误:语法错误,意外的T_STRING输入 /home/a4101275/public_html/index.php,第9行

Parse error: syntax error, unexpected T_STRING in /home/a4101275/public_html/index.php on line 9

第9行是我正在使用file_get_contents的地方.

line 9 is where I am using the file_get_contents.

错误是什么意思,我该如何解决?

What does the error mean and how do I fix it?

推荐答案

您必须正确使用转义符.在单引号封装的字符串中不能包含单引号(').它打破了.为了继续该字符串并使PHP从字面上解释您的内部单引号,您必须使用\对其进行转义.

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");

Parse error: syntax error, unexpected T_STRING通常表示您在该行某处有错误的字符串,以供将来参考.

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

这篇关于解析错误:语法错误,PHP中出现意外的T_STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆