为什么我会在这一行上获得Parse error: syntax error, unexpected T_VARIABLE
?PHP:解析错误:语法错误,意外T_VARIABLE当调用变量时
$fieldLabel = '<label for=".'$fieldNameStripped'.">.'$fieldName'.</label>';
为什么我会在这一行上获得Parse error: syntax error, unexpected T_VARIABLE
?PHP:解析错误:语法错误,意外T_VARIABLE当调用变量时
$fieldLabel = '<label for=".'$fieldNameStripped'.">.'$fieldName'.</label>';
您的线路应该是这样的
$fieldLabel = '<label for="' . $fieldNameStripped . '">' . $fieldName . '</label>';
$fieldLabel = '<label for="'.$fieldNameStripped.'">'.$fieldName.'</label>';
是你应该怎么做。
在你做了什么,有两个问题:
当使用.
进行连结,你应该确认该字符串的.
双方应"properly closed"
。
另外,假如你有$var = 1;
而你echo '$var';
你没有得到1
。你得到$var
作为输出。
$fieldLabel = '<label for="'.$fieldNameStripped.'">'.$fieldName.'</label>';
因为你不使用PHP正确 - 语法错误:
$fieldLabel = '<label for="' . $fieldNameStripped . '">' . $fieldName . '</label>';
^^^^ ^^^
你有串联运营商内部的串,所以你根本没有连接在一起。
尝试
$fieldlabel = <<<EOL
<label for="$fieldNameStripped">$fieldName</label>
EOL;
here文档做出这样的事情琐碎,并远远更容易阅读。使用现代语法高亮编辑器,变量甚至可以为您突出显示。
你也可以这样准备你的字符串: $ fieldLabel =“{$ field-> name}”;
这里双引号围绕外部字符串表示PHP将解析其中的变量。然而,你必须避免双引号。我已经更改了$ fieldName变量,以显示如何将变量包含在对象属性等项目的{}括号中(我倾向于将它们用于字符串中的常规变量,因为我认为它是更好的惯例)。
-1。你没有回答关于*为什么会出现解析错误的问题。 – 2012-12-26 01:23:42