Question:
PHP linebreak problem?
Zombie Jhakkaas
2008-01-25 09:08:16 UTC
Hi!
I am starting to learn PhP. I've installed easyPhP latest version (not beta). but there's a problem
I am not seeing linebreaks in the browser output. instead it'll show everything in the same line.
eg print " $myname\n"; print "$yourname\n";
would be printed $myname$yourname, instead of
$myname
$yourname
I even tried using '
' tags in html islands, but neither is working.
Can anybody suggest me something on this
Four answers:
anonymous
2008-01-25 09:22:39 UTC
use:



echo '$myname
';

echo '$yourname';





\n only affects the source code, not the browser output.



If you want to print the values of $myname and $yourname, use double quotation marks instead.
anonymous
2008-01-25 17:46:23 UTC
They're right, you would usually have to put the
tag in a string literal and display it directly onto the browser; however, php servers are programmed to recognize certain characters within a string..to cut to the chase, here's how you would go about solving this...



$printMe =



$myname +

"

"

+ $yourname



what this does, it stores within the printMe string a literal containing line breaks, which is the purpose of concatenating the strings to together!

now, use the function nl2br(); to replace the line break in the sstring!



nl2br($printMe);





Hope this helps!
daa
2008-01-25 17:20:36 UTC
You need to use html breaks. Put the break just after the variable, where you have the \n now.
U Can't Handle The Truth
2008-01-25 17:18:04 UTC
you have to print the


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...