Small problem with PHP new line character..

eternalsolitude

New Member
Messages
13
Reaction score
0
Points
0
I set up an xampp server on my computer to test out script without having to load a remote page every time I update the page. The problem is when I insert "\n" ion my server it will insert a new line, but on x10 it does not. How can I get it to insert a new line if "\n" or "\r" will not work? Thanks in advance.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
If you would post the code [in code or php brackets] , we might be able to see what the problem is.
 

eternalsolitude

New Member
Messages
13
Reaction score
0
Points
0
Okay, here's an example of where It's giving me a problem
Code:
echo "Hello,\n how are you today?"
I want it to output this:
"Hello,
how are you today"

But instead I get this..
"Hello,\nhow are you today?"

Oh. wow, that doesn't accurately show it. I would have to use a <br>.. Well what I'm wanting is a break each line of html echoed from php.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Are you saying that exact code on x10hosting produces that output?
 

eternalsolitude

New Member
Messages
13
Reaction score
0
Points
0
What I was trying to say is when I put
Code:
echo "<html>\n";
echo "<head>\n";
I want the actual document to have a line break after the tag <html> and <head>. I was expecting \n to do this, but I was just informed by one of my friends that the php variable "PHP_EOL" is what you use for this.. Sorry for wasting your time.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
"\n" should give you a line feed, as long as it's in a double quoted string.

Try the following exactly as typed:
PHP:
<?php
header('Content-type: text/plain');
echo "Hello,\nhow are you today?";
?>
Do you get a literal '\n' in the output? Or do you just not get a line break when you view the page in a browser? If the latter, it's because HTML treats line breaks the same as any other whitespace outside of <pre> elements and elements with certain values for the CSS white-space property. In HTML, almost all of the time there's a better choice than <br/>; usually, <br> isn't semantic. Instead, you should be using something like <p> or a list (<ul>, <ol> or <dl>).
 
Last edited:
Top