0

我引用了 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;
?>
4

1 回答 1

3

That is called PHP's Heredoc syntax. It's there to help you mark up strings without worrying about quotes.

A simpler example would be:

$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);

See the PHP Manual Entry on Strings for more information.

于 2012-10-02T17:11:20.777 回答