我试图运行此代码以多行打印输出,但它不按预期工作。Heredoc无法正常工作。 (PHP)
<?php
$author = "Bill Gates";
$text = <<<_END
Success is a lousy teacher.
It seduces smart people into thinking they can't lose.
-$author
_END;
echo $text;
?>
压痕是完全没有问题,但仍然输出为一行。
下面是输出
我觉得有我在代码中的错误,所以我从PHP官方网站
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
/* More complex example, with variables. */
class foo
{
var $foo;
var $bar;
function foo()
{
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');
}
}
$foo = new foo();
$name = 'MyName';
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>
即使这段代码复制下面的代码在一行中输出。 Output 2
那么,为什么会发生这种情况呢?什么是错误? 在此先感谢!
为什么不只是使用一些HTML ?.这不是那么困难,而且看起来会更好。你甚至可以自定义字体和颜色。 – Farini