-3

我的 php 代码给出了以下错误:

syntax error, unexpected '{' on line 8

PHP代码:

$data = '<?php
# 1 = ON; 0 = OFF.  
$str = '{                           //line 8
 "name": "10.000000,106.000000",
     "Status": {
     "code": 200,
     "request": "geocode"
 },
  "Apps": [ {
  "App1": 1,
  "App2": 0,    
  "App3": 1,
  "App4": 0,
  "App5": 0,
  "App6": 0
 } ]
 }';
   echo $str;
 ?>';

我是php的新手。谁能帮我找出我错在哪里?谢谢。

4

2 回答 2

4

那是因为'这里的第二个:

        +-- open string constant
        V
$data = '<?php
    # 1 = ON; 0 = OFF.  
    $str = '{   
           ^
           +-- close string constant

正在终止字符串常量。您可能想逃避它(以及在 final 之前的另一个echo),例如:

$data = '<?php
    # 1 = ON; 0 = OFF.  
    $str = \'{   
       blah, blah, blah
    }\';
    echo $str;
?>';
于 2013-03-12T06:40:58.083 回答
1

您的字符串在字符之前被单引号(撇号)终止{。使用转义'字符\'

$data = '<?php
# 1 = ON; 0 = OFF.  
$str = \'{                           //line 8
 "name": "10.000000,106.000000",
     "Status": {
     "code": 200,
     "request": "geocode"
 },
  "Apps": [ {
  "App1": 1,
  "App2": 0,    
  "App3": 1,
  "App4": 0,
  "App5": 0,
  "App6": 0
 } ]
 }\';
   echo $str;
 ?>';
于 2013-03-12T06:40:58.140 回答