PHP的标记符<<<theEnd有个很有意思的问题,如果你运行下面这段代码
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>测试程序</title>
</head>
<body>
<?php
echo "你好\n";
$variable = '啊哈哈';
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;
?>
</body>
</html>
会得到Parse error: syntax error, unexpected end of file in的错误
原来是因为标记符号必须顶头写,好像所有语言的标记符都是这样的,比如汇编。所以正确的用法是:
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>测试程序</title>
</head>
<body>
<?php
echo "你好\n";
$variable = '啊哈哈';
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;
?>
</body>
</html>
码农场