<?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;
?>
这个代码提示( ! ) Parse error: syntax error, unexpected $end in D:\wamp_code\test.php on line 29,也就是最后的"?>"错误,什么原因,大神
$this -> foo = 'Foo' ;
$this -> bar = array( 'Bar1' , 'Bar2' , 'Bar3' )
少了个分号
定界符“<<<”的后面紧接着的是定界标识符。标识符由字母、数字或下划线构成,并且不能以数字开始。结尾的标识符必须定格书写,其前不能有任何其他字符。
EOD;2处结束前面的空格都要去掉
$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;
//上面取对象属性要去掉->前后空格,要不是取$foo值会报错Object of class foo could not be converted to string。取数组值用{}界定好导入的变量,可以有空格