PHP closing tag deletes the line feed

Viewed 1624

I'm doing an experiment, an html preprocessor like SLIM or Jade.

This is the PHP code that seems right:

nav
  ul id: "test"
    li
      @<?= $Var; ?>
    li
      @About
    li
      @Contact

This is the expected pre-processed html (yes, $Var == "Test"):

nav
  ul id: "test"
    li
      @Test
    li
      @About
    li
      @Contact

However, in the browser I get this wrong text as the pre-processor html:

nav
  ul id: "test"
    li
      @Test    li
      @About
    li
      @Contact

Lastly, there are two ways to make it correct.

  1. Adding the break line manually:

    nav
      ul id: "test"
        li
          @<?= $Var . "\n"; ?>
      li
        @About
      li
        @Contact
    
  2. Writing a space after the PHP closing tag (??).

Why is the first case, <?= $Var; ?>, ignoring the line feed after the closing PHP tag? I couldn't really find anything since google brought too many results about why you should ignore the closing tag for every search I did and not what I wanted to find.

1 Answers
Related