Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
代码片段:
$str = "text"; echo "str variable contains $str";
此代码返回:
str 变量包含文本
如何在不关闭单引号的整个回声的情况下返回以下字符串?我想以某种方式 esape 变量仍然使用双引号,如下所示:
str 变量包含 $str
echo "str variable contains \$str";
如果要自动执行此操作,请使用str_replace().
str_replace()
$str = "text"; $text = "str variable contains $str"; $text = str_replace('$', '\$', $text); echo $text;