Escaped characters substitution not working in double quote

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alisaWL
Forum Newbie
Posts: 4
Joined: Tue Jun 30, 2009 5:03 am

Escaped characters substitution not working in double quote

Post 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.
Last edited by Benjamin on Tue Jun 30, 2009 10:34 am, edited 1 time in total.
Reason: Changed code type from text to php.
BornForCode
Forum Contributor
Posts: 147
Joined: Mon Feb 11, 2008 1:56 am

Re: Escaped characters substitution not working in double quote

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Escaped characters substitution not working in double quote

Post 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.
BornForCode
Forum Contributor
Posts: 147
Joined: Mon Feb 11, 2008 1:56 am

Re: Escaped characters substitution not working in double quote

Post by BornForCode »

jayshields rocks :drunk:
Post Reply