我有一个关于php nowdoc的问题

时间:2011-09-08 23:54:05

标签: php

我有一个关于php nowdoc的问题

<?php
$test = <<< test
<b>my name is $name</b>
test;
echo $test;
?>

我想输出:

我的名字是$ name,但我需要这样做:

<?php
$test = <<< test
<b>my name is \$name</b>
test;
echo $test;
?>

我该如何自动完成?

我的意思是这句话。

感谢。

3 个答案:

答案 0 :(得分:1)

你有什么heredoc,而不是nowdoc。要使其成为nowdoc,请将test括在引号中。然后,您不需要添加反斜杠。

<?php
$test = <<< 'test'
<b>my name is $name</b>
test;
echo $test;
?>

从其他地方的评论来看,似乎你使用的是heredoc而不是nowdoc,因为你拥有的PHP版本不支持nowdocs。没有办法用heredoc做你想要的事 - 这就是为什么添加了nowdocs的原因。您需要升级到较新版本的PHP,或者考虑采用不同的方式来满足更高级别的要求。

答案 1 :(得分:0)

答案 2 :(得分:0)

heredoc和nowdoc都没用。

如果你遇到这样的问题,你最有可能解决你的问题,而不是最好的方法,并且有一个更好的解决方案。