Page 1 of 1

Escaped characters substitution not working in double quote

Posted: Tue Jun 30, 2009 5:09 am
by alisaWL
I have some strange behavior on this very simple test case:

Code: Select all

<?php
echo 'single: my \n \$ \t string';
echo '<br/>';
echo "double: my \n \$ \t string";
?>

Code: Select all

output:
single: my \n \$ \t string
double: my $ string
What am I missing?
Shouldn't there be a newline and a tab in the double quote string?

Thank you.

Re: Escaped characters substitution not working in double quote

Posted: Tue Jun 30, 2009 5:43 am
by BornForCode
In the double quoted string that \n have other meanings :) since are interpreted as escaping sequences.
For more details please check: http://www.php.net/manual/en/language.t ... tax.double

Re: Escaped characters substitution not working in double quote

Posted: Tue Jun 30, 2009 5:50 am
by jayshields
You won't see the effect of a new line or a tab in your browsers viewport. You will see it in the source code though.

You can change this by using the <pre> HTML tag.

Re: Escaped characters substitution not working in double quote

Posted: Tue Jun 30, 2009 5:53 am
by BornForCode
jayshields rocks :drunk: