PHP SimpleXML用法的语法说明

PHP SimpleXML用法的语法说明,php,syntax,Php,Syntax,我参考了PHP手册,但由于提前结束PHP标记,我得到了一个语法错误。显然,我是PHP新手,但我只是试图将xml指定为PHP字符串。这里有什么问题 <?php $xmlstr = <<<XML //Need a clarification on '<<<XML' if possible <?xml version='1.0' standalone='yes'?> //This is closing my php script and caus

我参考了PHP手册,但由于提前结束PHP标记,我得到了一个语法错误。显然,我是PHP新手,但我只是试图将xml指定为PHP字符串。这里有什么问题

<?php
$xmlstr = <<<XML //Need a clarification on '<<<XML' if possible 
<?xml version='1.0' standalone='yes'?> //This is closing my php script and causing error
<details>
<detail>
    <user>mcgraw</user>
    <dateA>09/11/1973</dateA>
    <inTime>9:00am</inTime>
    <outTime>6:00pm</outTime>
    <hours>9</hours>
    <notes>Monday</notes>
</detail>
<detail>
    <user>simpson</user>
    <dateA>08/23/1983</dateA>
    <inTime>9:00am</inTime>
    <outTime>5:30pm</outTime>
    <hours>8.5</hours>
    <notes>Thursday</notes>
</detail>
</details>
XML;
?>
//这将关闭我的php脚本并导致错误
麦格劳
09/11/1973
上午9点
下午六点
9
星期一
辛普森
08/23/1983
上午9点
下午5:30
8.5
星期四
XML;
?>

这就是PHP的Heredoc语法。它可以帮助您标记字符串,而不用担心引号

一个简单的例子是:

$string = <<<STR_END_DELIMITER
This is some string, I can use ' and " freely, and it wouldn't break the string.
I can also use $variables inside, and they'll evaluate.
When I'm done with the string, I'll need to type STR_END_DELIMITER; on a fresh line, without anything else (not even spaces!)
STR_END_DELIMITER;
do_stuff_with_string($string);

$string=,称为PHP的herdoc语法。它可以帮助您标记字符串,而不用担心引号

一个简单的例子是:

$string = <<<STR_END_DELIMITER
This is some string, I can use ' and " freely, and it wouldn't break the string.
I can also use $variables inside, and they'll evaluate.
When I'm done with the string, I'll need to type STR_END_DELIMITER; on a fresh line, without anything else (not even spaces!)
STR_END_DELIMITER;
do_stuff_with_string($string);

$string=您能给我们确切的错误消息吗?发出错误信号的唯一东西是语法突出显示-dreamweaver打开和关闭php标记是红色的-xml标题关闭标记被读取为关闭php标记,并以红色书写。这仅仅是dreamweaver的问题吗?您能给我们确切的错误消息吗?唯一表明错误的是语法突出显示-dreamweaver打开和关闭php标记是红色的-xml标题关闭标记被读取为关闭php标记,并以红色书写。这只是dreamweaver的问题吗?根据文档,我的语法还可以,但我在CS6 dreamweaver中遇到了一个错误,因为@mcG73如果错误是dreamweaver中突出显示的语法错误,而不是php中的错误,那么很可能Dreamweaver不理解字符串语法。@mcG73:我的PHPStorm不会抛出任何此类错误,当我运行页面时,PHP也不会抛出此类错误。@mcG73也许您可以尝试其他编辑器?PHPStorm IMO已经很好了,但是有一些合理的免费选项:这是dreamweaver特有的问题,我刚刚提交了一份bug报告。感谢您的帮助根据文档,我的语法还可以,但是我在CS6 Dreamweaver中遇到了一个错误,因为@mcG73如果该错误是Dreamweaver中突出显示的语法错误,而不是php中的错误,那么Dreamweaver很可能不理解字符串语法。@mcG73:my PHPStorm不会抛出任何此类错误,当我运行页面时,PHP也不会运行。也许你可以尝试其他编辑器?PHPStorm IMO已经很好了,但是有一些合理的免费选项:这是dreamweaver特有的问题,我刚刚提交了一份bug报告。谢谢你的帮助