In PHP, how to express a string literal on multiple lines without new lines appearing in the rendered text?

Sometimes in PHP, when I need to assign a large string literal to a variable, I split the quoted string into several lines so that it can be read without scrolling 300 characters to the right. My problem is that PHP includes a new line in the actual line when it is displayed in the application. Is there a way to avoid a newline, or is there a better way to express a string literal on multiple lines? I know that I could use concatenation, but I was hoping for a more elegant solution.

Running on Debian, if that matters.

+6
source share
2 answers

On a large line, I prefer to use the heredoc style, also you can see several alternatives in the PHP documentation on strings

+2
source

Command str_replace('\n',"",$string); replaces a new line. See the PHP documentation .

-3
source

Source: https://habr.com/ru/post/907197/


All Articles