nowdoc

类型-字符串:Heredoc语法结构和Nowdoc语法结构

[亡魂溺海] 提交于 2020-03-01 03:07:01
Heredoc和Nowdoc最主要的作用就是输出大量字符串,特别是HTML的字符串,他可以避免你在使用''或""时的转译问题。 他俩的语法规则不是很难,但是挺怪异,据说是继承于 Perl风格的字符串输出技术,反正是和别的PHP代码挺不像的。 Heredoc就像是双引号,他可以输出字符串并且识别里面的$变量,而且里面有'和"可以直接输出不必转译。可以说方便很多,但是其自身的语言要求也很严谨,一定要仔细。 来看看手册对Heredoc的说明: heredoc句法结构: <<< 。在该提示符后面,要定义个标识符,然后是一个新行。接下来是 字符串 本身,最后要用前面定义的标识符作为结束标志。 结束时所引用的标识符 必须 在一行的开始位置, 而且,标识符的命名也要像其它标签一样遵守PHP的规则:只能包含字母、数字和下划线,并且不能用数字和下划线作为开头。 ( 要注意的是结束标识符这行除了 可能 有一个分号( ; )外,绝对不能包括其它字符。这意味着标识符 不能缩进 ,分号的前后也不能有任何空白或tabs。更重要的是结束标识符的前面必须是个被本地操作系统认可的新行标签,比如在UNIX和Mac OS X系统中是 \n ,而结束标识符(可能有个分号)的后面也必须跟个新行标签。 ) 举一个heredoc和""对比的例子: <?phpecho"<h1>我的午餐</h1> <font color=\

Why do these Heredoc and Nowdoc cause errors?

限于喜欢 提交于 2019-12-12 07:14:25
问题 I've already found some solutions, but can't know what happened... Example 1: <?php echo <<< EOD test EOD; Example 2: <?php echo <<< 'EOD' test EOD; Output 1,2: PHP Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) Example 3: <?php echo <<< EOD test EOD; ?> Example 4: <?php echo <<< 'EOD' test EOD; ?> Example 5: <?php echo <<< EOD test EOD; 'dummy'; Example 6: <?php echo <<<

Why do these Heredoc and Nowdoc cause errors?

坚强是说给别人听的谎言 提交于 2019-11-30 10:21:40
I've already found some solutions, but can't know what happened... Example 1: <?php echo <<< EOD test EOD; Example 2: <?php echo <<< 'EOD' test EOD; Output 1,2: PHP Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) Example 3: <?php echo <<< EOD test EOD; ?> Example 4: <?php echo <<< 'EOD' test EOD; ?> Example 5: <?php echo <<< EOD test EOD; 'dummy'; Example 6: <?php echo <<< 'EOD' test EOD; 'dummy'; Output 3,4,5,6: test You probably have spaces after the terminator in your

Advantages / inconveniences of heredoc vs nowdoc in php

别说谁变了你拦得住时间么 提交于 2019-11-27 18:29:13
As a newbie, I have been advised to preferably use heredoc compared to too many nested codes (see Unexpected T_ELSE in php code ). But I can't manage to understand if there is a significant difference between heredoc and nowdoc. What would be the advantages for heredoc and nowdoc compared to the other one that would be important for a newbie to understand (i.e. not very minor advantages but important to understand for me). deceze Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc.

Advantages / inconveniences of heredoc vs nowdoc in php

纵饮孤独 提交于 2019-11-26 19:28:02
问题 As a newbie, I have been advised to preferably use heredoc compared to too many nested codes (see Unexpected T_ELSE in php code). But I can't manage to understand if there is a significant difference between heredoc and nowdoc. What would be the advantages for heredoc and nowdoc compared to the other one that would be important for a newbie to understand (i.e. not very minor advantages but important to understand for me). 回答1: Nowdocs are to single-quoted strings what heredocs are to double