How to output on a newline in php | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to output on a newline in php

14th Feb 2020, 5:58 PM
Patrick Ikechukwu (iykey)
Patrick Ikechukwu (iykey) - avatar
4 Answers
+ 5
Use the newline Characters ' \n ' or ' \r\n ' You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHP nl2br() function which inserts HTML line breaks before all newlines in a string.
14th Feb 2020, 6:10 PM
SHADOW 🌀
SHADOW 🌀 - avatar
+ 1
You can't use \n to issue a line break by echo. When you do echo here the output is written into a web page body, thus you need to use HTML line break. echo "My name is Patrick.<br />"; echo "I'm learning PHP on SoloLearn."; P.S. Can you please edit the tags? It is not recommended to write your question into the tags. But you can keep PHP in there, it is a relevant language in regards to the question 👌
14th Feb 2020, 7:51 PM
Ipang
0
Alright. Let me try that. Thanks.
14th Feb 2020, 6:18 PM
Patrick Ikechukwu (iykey)
Patrick Ikechukwu (iykey) - avatar
0
Hi I used the '\n' in Sololearn code playground but it seems not to work. This is exactly what I wrote: echo "My name is Patrick. '\n' "; echo "I'm learning PHP on Sololearn.";
14th Feb 2020, 7:09 PM
Patrick Ikechukwu (iykey)
Patrick Ikechukwu (iykey) - avatar