How do I write the <<<TOC thing in PHP?

99封情书 提交于 2019-12-11 17:57:59

问题


I forgot how to write the one command that looked something like this

<<TOC


bla bla

bal bal


TOC;

how was it written again?


回答1:


These are called heredocs.




回答2:


It works like this:

$foo = <<<TOKEN
multi
line
string
TOKEN;

TOKEN can be anything you want as long as you being and end the heredoc with the same exact thing.




回答3:


Yes that is corect syntax for using a heredoc, however make sure that TOC; line is not indented or it will not work. FYI you can call it anything you want such as HTML not just TOC.




回答4:


Good Examples:

$foo = <<<TOKEN⁋
multi⁋
line⁋
string⁋
TOKEN;⁋

However, these don't work

$foo = <<<TOKEN‧anything here⁋
multi⁋
line⁋
string⁋
TOKEN;‧anything here⁋
$foo = <<<TOKEN
multi⁋
line⁋
string⁋
‧TOKEN;
$foo = <<<TOKEN
multi⁋
line⁋
string⁋
→TOKEN;

The closing token must be on its own line, hard up against the left margin, followed directly with its following semi colon, followed directly with a carriage return.



来源:https://stackoverflow.com/questions/571894/how-do-i-write-the-toc-thing-in-php

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