0

Im referencing the PHP manual but Im getting a syntax error due to the early closing php tag-Obviously Im a newb to php but Im only attempting to assign the xml as a php string. Whats the problem here?

<?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;
?>
2
  • can you give us the exact error message? Commented Oct 2, 2012 at 17:16
  • the only thing signaling the error is syntax highlighting- dreamweaver open and closing php tags are red- the xml heading closing tag is being read as the closing php tag and it is written in red. Is this only a dreamweaver issue? Commented Oct 2, 2012 at 17:28

1 Answer 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.

Sign up to request clarification or add additional context in comments.

5 Comments

according to the doc my syntax is okay, but im getting an error with CS6 Dreamweaver because the <?xml version='1.0' standalone='yes'?> <----is used as the closing tag to the php script and the code following is not being seen.
@mcG73 If the error is a highlighted syntax error in Dreamweaver, rather than an error from php, then it is highly likely that Dreamweaver does not understand the string syntax.
@mcG73: My PHPStorm doesn't throw any such errors, nor does PHP when I run the page.
@mcG73 perhaps you could try another editor? PHPStorm IMO is as good as it gets, but there are some reasonable free options: stackoverflow.com/questions/6166/…
its a dreamweaver specific issue, I just submitted a bug report. Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.