PHP:没有连接的字符串中的变量

duk*_*vin 10 php string

如果我在这个字符串中有一个变量$ var: echo "Hello, there are many $vars";

Php寻找variable $vars而不是$var.

没有连接像:"Hello, there are many $var" . "s";
有没有另一种方法来做到这一点,比如某种逃避角色?

Tri*_*tan 26

在php中你可以像这样转义变量

echo "Hello, ${var}'s head is big";
Run Code Online (Sandbox Code Playgroud)

或者喜欢

echo "Hello, {$var}'s head is big";
Run Code Online (Sandbox Code Playgroud)

参考这里下转义字符节


Mad*_*iha 6

您可以使用{}来正确转义您的变量。考虑以下示例:

echo "There are many ${var}s"; #Or...
echo "There are many {$var}s";
Run Code Online (Sandbox Code Playgroud)

工作示例