php Heredoc 结构的字符串示例
Heredoc 结构的字符串与双引号("")字符串对比分析
<?php $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; /* 含有变量的更复杂示例 */ 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; echo "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"; ?>
如上的运行结果中:
Heredoc 结构就象是没有使用双引号的双引号字符串,这就是说在 heredoc 结构中单引号不用被转义,但是上文中列出的转义序列还可以使用。变量将被替换,但在 heredoc 结构中含有复杂的变量时要格外小心。
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23