Skip to content
Advertisement

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=%snalias2=%snalias3=%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.

Advertisement

Answer

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 rn.

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)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement