For some strange reason, inserting Show The images of the results of examples in books and other documentations seems just alright. I'm currently using XAMPP and already used WAMPP with the same actual result. Why is that? Edit: It seems that I cannot understand the concept after comparing your answers with this: PHP Linefeeds (\n) Not Working Edit: Sorry I didn't realized that the link above is referring to a php code writing to a file. I just wonder why I have these few php sample programs that uses \n even though it outputs in a webpage. Thanks everyone.
asked Sep 13, 2012 at 16:24
4 When you run a PHP script in a browser, it will be rendered as HTML by default. If the books you’re using show otherwise, then either the code or the illustration is inaccurate. You can use “view source” to view what was sent to the browser and you’ll see that your line feeds are present.
This will render in your browser as:
If you need to send plain text to your browser, you can use something like:
This will output:
PHP Linefeeds (\n) Not Working is referring to sending output to a file rather than the browser.
answered Sep 13, 2012 at 16:49
HerbertHerbert 5,5602 gold badges25 silver badges34 bronze badges 4 You should be
looking for answered Sep 13, 2012 at 16:26
BojanglesBojangles 97k48 gold badges169 silver badges205 bronze badges The That command will insert a new line character. From the sounds of it, you're using a browser to view your output. Note that if you wrote an HTML file that had a body contents that looked like:
The browser rendering would not include the new lines, and would instead just show "This is a test" If you want to see the newlines, you could view source, and you'll see that the source code includes the new lines. The rule of thumb is that if you need new lines in a browser, you need to use HTML (e.g. answered Sep 13, 2012 at 16:40
ernieernie 6,24722 silver badges27 bronze badges
The browser doesn't output a new line each time the HTML file goes to the next line. answered Sep 13, 2012 at 16:25
BgiBgi 2,50312 silver badges11 bronze badges You can use the nl2br function to convert As said before, HTML does not render
Stano 8,3706 gold badges28 silver badges42 bronze badges answered Sep 13, 2012 at 16:27
If you are working with HTML (viewing the result in browser for example) you have to use the HTML way of linebreaks which is: answered May 5, 2017 at 8:19
Hasan A YousefHasan A Yousef 20.3k22 gold badges118 silver badges177 bronze badges
answered Jan 23, 2020 at 7:18
Kunal RautKunal Raut 2,3872 gold badges8 silver badges25 bronze badges PHP outputs on the browser and browser only render output in HTML, any other output format will be ignored by the browser. If you want browser to keep your standard output format as it is, you should enclose your output
under HTML's
This will be rendered as
Alternatively, you can mention content type to be plain text in the header:
This will tell the browser to render the output as plain text. And the browser will encolse the output automatically in answered Aug 4 at 8:19
solution is echo nl2br or=> <br> answered May 25 at 13:53
1 Not the answer you're looking for? Browse other questions tagged php xampp or ask your own question.Can we use \n in PHP??> Using new line tags: Newline characters \n or \r\n can be used to create a new line inside the source code.
Is new line \n or n?In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
What is \n mean in HTML?The \n character matches newline characters.
What is Br in PHP?It is an in-built function of PHP, which is used to insert the HTML line breaks before all newlines in the string. Although, we can also use PHP newline character \n or \r\n inside the source code to create the newline, but these line breaks will not be visible on the browser. So, the nl2br() is useful here.
|