What is <<<_END?

末鹿安然 提交于 2019-11-30 18:07:05

It's the start of a heredoc. you can do:

$data = <<< _END

You can write anything you want in between the start and end

_END;

_END can be just about anything. You could put EOF or STUFF. as long as you use the same thing at the start and the finish.

This signifies the beginning of a heredoc (a multi-line string that allows you to use quotation marks in the middle, unescaped) that ends when you encounter the _END

It can be useful to define HTML in one of these if the goal is to assign it to a variable or pass it to a function rather than printing it to the web server immediately.

That syntax is called heredoc

<<<_END
some text
_END

Basically, it's a way of writing a string without worrying about escaping quotes and so on.

As you've mentioned, it doesn't really provide a lot of benefit over other string formats - although, it does mean you can write a block of HTML without escaping out of PHP with ?>

It also isn't too popular as its use generally goes against the practice of seperating content from logic by embedding the content in the middle of your script.

Does this help? http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

It allows you to echo out a block of text (just the same as with echo "words";), but without using the beginning/ending quotes, and without having to escape contained double quotes. Read the manual link above for more detail.

It's a heredoc. It's just a way of defining a string.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!