How to output on a newline in php | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to output on a newline in php

14th Feb 2020, 5:58 PM
Patrick Ikechukwu (iykey)
Patrick Ikechukwu (iykey) - avatar
4 Respostas
+ 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