Have I misunderstood what heredoc should do?

后端 未结 4 1055
小鲜肉
小鲜肉 2021-01-20 13:03

I\'m very new to PHP so I know I am missing something obvious here - I thought the heredoc function is supposed to retain formatting, line breaks, etc. But whenever I test

4条回答
  •  独厮守ぢ
    2021-01-20 13:23

    HEREDOC is not a function, it is a method for specifying string delimiters that allows you to forgo escaping quotes within the heredoc (I like it because good text editors will syntax highlight their contents based on the heredoc name).

    HEREDOCs do preserve all whitespace, newlines, etc. I think you are probably looking at the results in a browser. Browsers generally trim all whitespace, newlines, spaces, and tabs included, down to a single space. Try looking at it on the command line, a text email, or a text file.

提交回复
热议问题