+ 1
how can i have new line in php?
6 odpowiedzi
+ 6
Displaying a new line depend on where your script will output
1- If you are using your script to print output on a command line or to write into a file you can use "\n" or "\n\r" escaping characters to generate a new line
A common mistake is to use \n inside a single quote pair '\n' which result to print the string \n as it , because echo and printing of string between single quotes will print the string as it is ,
while using double quotes will result in evaluating of string between double quotes and print the evaluation output
Example1(error) :
echo 'Hi brother \n How are you ?';
Output:
Hi brother \n How are you ?
Example2(correct)
echo "Hi brother \n How are you ?";
Output :
Hi brother
How are you ?
As \n is an escape character , so it needs to be evaluated to be converted while outputting to a crlf special character
2-If you are using your script to return output to a web page via a browser a new line can be outputted by echoing or printing the html break line tag :<br>
Or using the paragraph tag : <p> or using the div tag :<div>
Php is a scripting language and the output of a new line depend where your script output will go
Happy scripting 😍
+ 1
depends on your host system, but un Unix like systems it is
echo "first line\nsecond line";
echo with double quotes (" ") not single (' ') and add new line symbol (\n) (backslash)
+ 1
\n is use for new line
+ 1
\n
symbol
0
data antt
0
Beside \n you can use <br> also