Php and newlines: what do i need to know?

I have some questions about \r\n:

  • Does the new line depend on the browser? (and not how they are displayed in the browser, but how it <textarea>sends them to php via an HTTP request)
  • Are new lines system dependent? (where does php run)
  • will php apply implicit conversion?
  • Will mysql use implicit conversion?

Thanks in advance!

+3
source share
6 answers
  • Does the new line depend on the browser?
    • No. Use <br>to get a new line in the browser.
  • Are new lines system dependent? (where does php run)
    • yes: \non OSX, \non Unix / Linux, \r\non Windows
  • php ?
  • mysql ?
+6

, \r \n - , ' ' () \t (). (script, pre ..) . (\r, \r\n, \n).

textarea, \r\n.

php , . , php . php , .

, :

print_r("
" === "\r\n");

, . .

, (, ), , , .

, PHP MySQL .

+2

<br> , \n .

\r

MySQL

0

, nl2br, , , HTML (<br />).

0

The system independent method uses the constant PHP_EOL.

New lines are browser independent, external tag with CSS white-space: pre you must execute the nl2br () php function to convert strings to BR tags.

0
source

It was a great success for me that in single quotes, 'like\nthis'escape sequences (for example, \n) would not be interpreted. You must use double quotes "like\nthis"to get the actual newline.

0
source

All Articles