简体   繁体   中英

PHP difference between \n and just new line in sprintf and writing files

I'm developing in LAPM environment. What is difference between "\\n", just new line?

There are several examples.

example 1

$content = sprintf("alias=%s
alias2=%s
alias3=%s", "apple", "banana", "cosmos");

example 2

$content = sprintf("alias=%s\nalias2=%s\nalias3=%s", "apple", "banana", "cosmos");

And when i create a file with this content,

result of example 1

alias=appler
alias2=banana
alias3=cosmos

result of example 2

alias=apple
alias2=banana
alias3=cosmos

What is the "r" of alias=appler in result of example 1?

What is the difference between "\\n" and new line of enter key action?

I'm sorry for being not good at English.

Thank you.

There is basically no difference between \\n and newline generated by [ENTER] key, but only until you are running on a Linux-based text-editor or IDE. In windows environment the [ENTER] key is represented by \\r\\n .

I have no explanation for that r in the first example, there must be some problem in the way you are executing or showing it. Is there any other code? (For example the file-writing one)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM