2011-08-29 46 views
4

我不知道我在做什麼錯在這裏,但我得到解析錯誤: 「解析錯誤:語法錯誤,意外','在...試圖使用回聲的逗號,而不是字符串連接

$msg= 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 
echo $msg; 

你能幫我嗎?由於速度較慢,我不想使用連接。

回答

2

在$味精由.將字符串之間,

$msg= 'This is ' . htmlentities($from, ENT_QUOTES, 'UTF-8') . ' and ' . 
     htmlentities($to, ENT_QUOTES, 'UTF-8') . ' dates statistic '; 

,或者直接回應:

echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 
3

Basicaly逗號分隔值參數。您正在嘗試將參數傳遞給變量但不回顯!

echo 'This is ', 
    htmlentities($from, ENT_QUOTES, 'UTF-8'), 
    ' and ', 
    htmlentities($to, ENT_QUOTES, 'UTF-8'), 
    ' dates statistic '; 
+0

非常感謝您的信息!不知道。 – Christine

2

回波接受用逗號separted多個值,變量分配沒有。

,將工作

echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 

$msg= 'This is '. htmlentities($from, ENT_QUOTES, 'UTF-8') . ' and ' . htmlentities($to, ENT_QUOTES, 'UTF-8') . ' dates statistic '; 
echo $msg; 
+0

非常感謝您提供這些信息!不知道。 – Christine

2

在字符串賦值您不能使用逗號,逗號只爲echo命令本身的工作。所以,如果你想避免串聯,你上面提到你需要這樣做:

echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'), 
     ' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 
+0

非常感謝您提供這些信息!不知道。 – Christine

1
echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 

中的逗號只能echo合作,而不是與變量賦值。

相關問題