输出与打印和EOF不工作


Output with print and EOF not working

 print <<< HERE
 <p>
 <img src="dado_$roll.png"
      alt="$roll"
      height="100px"
      width="100px" />
</p>
HERE;

上面的代码不能工作。我不知道为什么。

需要在结束HERE;标识符之后有一个回车或结束?>标记。参见代码中的注释。

<?php
print <<< HERE
 <p>
 <img src="dado_$roll.png"
      alt="$roll"
      height="100px"
      width="100px" />
</p>
HERE;
// make sure there's a carriage return here
// or add a closing ?> tag

你甚至可以有一个没有其他东西的//,只要HERE;下面有东西

否则,它会抛出:(如果错误报告是ON)

解析错误:语法错误,文件在…(路径/到/file)中意外结束在行X


  • 查阅以下手册

编辑:(测试输出)

$roll = "Roll_tag_text";
print <<< HERE
 <p>
 <img src="dado_$roll.png"
      alt="$roll"
      height="100px"
      width="100px" />
</p>
HERE;

HTML来源:(如果这是期望的结果)

<p>
 <img src="dado_Roll_tag_text.png"
      alt="Roll_tag_text"
      height="100px"
      width="100px" />
</p>

这就不那么令人困惑了,并且做了同样的事情:请记住,当使用"双引号时,PHP将允许在其中使用变量和它们的值。

<?php
 $string = '
   <p>
      <img src="dado_$roll.png"
        alt="$roll"
        height="100px"
        width="100px" />
   </p>
 ';
echo $string;