123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|402|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> Next Line in PHP

Sat, 03 Feb 2007, 17:33
Stealth
I am trying to figure out how to go to the next line in php. I think this is called a linefeed.

This code should work if I am not mistaken:


And in the source the output looks like:
one \n two

It should look like:
one
two

What am I doing wrong?

-=-=-
Quit posting and try Google.
Sat, 03 Feb 2007, 17:38
HoboBen
Try



Sat, 03 Feb 2007, 17:46
Stealth
Eh.. My PHP code gets messy when I do that. Do I have to do it that way?

-=-=-
Quit posting and try Google.
Sat, 03 Feb 2007, 18:20
JL235
Stealth, '\n' is correct. But if PHP is anything like Ruby then you need the text in double quotes not single.
Sat, 03 Feb 2007, 18:50
Stealth
Hmm..

I think you can use ' or ". Do I need to use a double quote instead?

-=-=-
Quit posting and try Google.
Sat, 03 Feb 2007, 19:37
JL235
Well in Ruby and Java both double and single quotes do different things. In Ruby a line written in single quotes will be taken literally, so '\n' prints "\n". But double quotes will scan the line for various things such as signs like '\n' which mean end of line.

In Java I believe single quotes is for a character, and Ruby also scans lines for code blocks '#{ }' allowing you to have code that runs inside a string (although it's mainly used to put variables in a string).

I don't know PHP, but I'd find it odd if both single and double quotes did exactly the same thing.

|edit| My original post had code block brackets not square brackets above, and don't forget the missing '%' bug in Mud Chat. Two perfect examples of my strings being read and changed before being written. |edit|
Mon, 05 Feb 2007, 06:05
Phoenix
Yes, DiablosDevil is right.

php.net: If the string is enclosed in double-quotes ("), PHP understands more escape sequences for special characters.

Mon, 05 Feb 2007, 11:19
JL235
Wow, and I don't even know PHP.
Wed, 28 Feb 2007, 19:09
garand
Guess who is being troubled with this now... . I tried the above and it is not working. The below code is just sample code to help me learn PHP but it won't go to a new line every time.



Check it out at php.krypton-media.com/newlinehelp.php
Wed, 28 Feb 2007, 19:23
garand
I fixed it!! (Google is my friend).