我有一个关于PHP nowdoc问题我有一个关于PHP nowdoc问题
<?php
$test = <<< test
<b>my name is $name</b>
test;
echo $test;
?>
我想输出:
我的名字是$名字,但我需要做的:
<?php
$test = <<< test
<b>my name is \$name</b>
test;
echo $test;
?>
我该如何做到自动?
我的意思是关于这个报价。
谢谢。
我有一个关于PHP nowdoc问题我有一个关于PHP nowdoc问题
<?php
$test = <<< test
<b>my name is $name</b>
test;
echo $test;
?>
我想输出:
我的名字是$名字,但我需要做的:
<?php
$test = <<< test
<b>my name is \$name</b>
test;
echo $test;
?>
我该如何做到自动?
我的意思是关于这个报价。
谢谢。
你有什么是定界符,而不是一个nowdoc。要使它成为一个nowdoc,请将test
用引号引起来。然后您不需要添加反斜杠。
<?php
$test = <<< 'test'
<b>my name is $name</b>
test;
echo $test;
?>
从您的评论别处,好像你使用定界符而不是nowdoc因为你的PHP版本不支持nowdocs。在使用heredoc之后,无法完成您的工作 - 这就是为什么要添加nowdocs的原因。您需要升级到更新版本的PHP,或者考虑满足您更高级别要求的不同方式。
不知道为什么有人低估了这一点。如果事实错误,请告诉我 - 我会更正或删除它。 –
heredoc和nowdoc都是无用的。
如果您遇到这样的问题,您最有可能解决您的问题,而不是最好的方法,并有一个更好的解决方案。
我知道关于nowdoc,但它只能在php 5.3中工作,有没有办法在php 5.1中做到这一点? – cssnb2329
你必须逃避它。你不能使用某种语言的功能,并希望它能做些什么。你不能让heredoc像nowdoc一样行事:)。 – Corbin