php Heredoc 结构的字符串示例
2021-02-04 17:14
标签:func 转义 span line 结果 com width UNC fun Heredoc 结构的字符串与双引号("")字符串对比分析 如上的运行结果中: Heredoc 结构就象是没有使用双引号的双引号字符串,这就是说在 heredoc 结构中单引号不用被转义,但是上文中列出的转义序列还可以使用。变量将被替换,但在 heredoc 结构中含有复杂的变量时要格外小心。 php Heredoc 结构的字符串示例 标签:func 转义 span line 结果 com width UNC fun 原文地址:https://www.cnblogs.com/ttaylor/p/13138143.htmlphp
$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";
?>
文章标题:php Heredoc 结构的字符串示例
文章链接:http://soscw.com/index.php/essay/50984.html