Forum Moderators: coopster
I am starting to learn php and I am alraedy struggeling with the basics. My PHP program is not showing any Line Breaks :-( I wrote a program "test.php". Instead of doing line breaks, he is doing everything in one line. I tried it on my local Windows machine with Apache installed as well as on my Webhoster's server.
<?php
echo " line 1 \n line 2 \n line 3";
echo nl2br ("line A");
echo nl2br ("line B");
echo nl2br ("line B");
?>
I start to feel stupid. Anybody an idea?
Thanks,
Benni
No stupidity here, just learning. :)
Maybe this example will help:
<?php $stringVariable = "line A \n line B \n line C"; echo nl2br($stringVariable); ?> nl2br replaces "newline" code (\n or the Windows equivalent \r\n) with an HTML "linebreak" (<br>). You were asking the nl2br function to replace newlines in a string that didn't have any! You wrote:
nl2br("line A"); You can see the difference here:
nl2br("line A \n line B"); In the second example, there is a newline to replace, so
nl2br will have something to do. Hope that helps!