创建包含用嵌套引号包装的变量的字符串时出现语法错误


syntax error in creating a string that contains a variable wrapped in nested quotes

此原因错误:

$xml .= "'t<team id='"$team['id']'"";

这不会导致错误:

$xml .= "'t<team id='"'"";

有什么问题吗?

可以去掉单引号:

$xml .= "'t<team id='"$team[id]'"";

或者您可以使用以下语法之一在双引号字符串内使用花括号:

$xml .= "'t<team id='"{$team['id']}'"";
$xml .= "'t<team id='"${team['id']}'"";

引用(向下滚动到"变量解析"部分)。

再举几个例子:

echo "$team[id]";
echo "{$team['first name']}"; // e.g. when there are spaces in key names
echo "{${getVarName()}}";     // e.g. when we cannot use $ directly

应该可以:

$xml .= "'t<team id='"$team[id]'"";

看看我是如何去掉id周围的单引号的。

试试这个:

$xml .= "'t<team id='".$team['id']."'";

Try This

$xml .= "'t<team id='"".$team['id']."'"";

也可以像这样使用大括号

$xml .= "'t<team id='"{$team['id']}'"";

我认为问题不在于双引号,而在于$team['id']。

你试过了吗?

$xml .= "'t<team id='"".$team['id']."'"";