escape sequences not working in php

stickybytes

Golden Member
Sep 3, 2003
1,043
0
0
I'm having problems using the escape sequences/strings in php. For example, when i write:

<?php
echo("Hello\nBye");
?>

The output ends up looking like:

Hello Bye

I have tried using printf, print, all with the same result. Additionally, \t , \r don't work. I know php is running properly because when i type phpinfo(), it works. Furthermore, i can write loops, all the usual php syntax works. I installed the latest version of wamp, version 2, that comes along with php 5.2.6. I am running windows xp.
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Look at the source code.

If you want the break, do it like, "echo("Hello<br />Bye");", and if you want it both ways, "echo("Hello<br />\nBye");"

Edit:

Look at the source code that it printed out (the web page). The page source, not the script source. Sorry for the confusion.
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
The reason is because the HTML editors read the entire page source as a single line of code. They don't respect page breaks unless it is put in there by the page markup. But the output does respect the escaped characters, so when you look at your page source, you will see it printed out nicely, but when you view the same thing in the editor, it is all on one line.

It is somewhat counter-intuitive at first, but then it makes more sense when you think about it, and it is actually a great help. There's something nice about having clean source code to fix problems from. It gets kind of hard trying to fix a form when it's all on one huge long line.

That same problem stumped me for a few hours when I first started coding in PHP, then I finally figured out why. hah