1

At the moment i am learning PHP and came across the heredoc syntaxis. I have read the php.net documentation but still couldn't fix the bug. I also tried the pre tags since it was adviced in another stackoverflow post, but that didn't fix it either.

I have a problem with ending the heredoc, i can't. It makes everything after it a comment. Could someone please help me out? Thanks in advance!

The code:

<?php
        $naam = "Carl";
        $adres = " Kruislaan 111";
        $woonplaats = " Utrecht";
        $naw = $naam . $adres . $woonplaats;

        //Resultaat "Carl Kruislaan 111 Utrecht"
        echo ("Gegevens: $naw");
        echo <<<EIND
        <pre>
        Salaris specificatie <br />maand: november jaar:2010
        plaats: $woonplaats <br/>
        Algemene gegevens:
        </pre>
        EIND;
    ?>

It gave me this error: Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\Webdesign\unit4\voorbeeld.php on line 25

It pointed to the closing html tag since it's still a comment:

See whole code if needed:

<!DOCTYPE html>
<html lang="nl">
<head>
    <title>Mijn php-script</title>
</head>
<body>
    <h3>Variabelen</h3>
    <?php
        $naam = "Carl";
        $adres = " Kruislaan 111";
        $woonplaats = " Utrecht";
        $naw = $naam . $adres . $woonplaats;

        //Resultaat "Carl Kruislaan 111 Utrecht"
        echo ("Gegevens: $naw");
        echo <<<EIND
        <pre>
        Salaris specificatie <br />maand: november jaar:2010
        plaats: $woonplaats <br/>
        Algemene gegevens:
        </pre>
        EIND;
    ?>
</body>
</html>
Oussama
  • 425
  • 1
  • 5
  • 7

1 Answers1

1

Make sure your ending EIND closing tag does not have spaces or other characters in front of it. I don't know much php syntax, but this is similar to bash or ksh scripts. So that was basically my guess.

YoYo
  • 9,157
  • 8
  • 57
  • 74
  • Thanks for the advice! It worked. The problem was that it even counted the tabs. The solution was to remove the tabs :)! – Oussama Oct 24 '15 at 08:42
  • 2
    That's probably why there is this red-box warning in the manual you've linked to: `Warning It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented [...]` – VolkerK Oct 24 '15 at 09:54
  • Grin - yeah, it is quite plainly there. Suspected as much, that's why I asked OP for the link. – YoYo Oct 24 '15 at 19:44
  • VolkerK, sorry, but i didn't know it even counted the TABs.. Anyways thanks! – Oussama Oct 28 '15 at 14:26