Page 1 of 1

Escape Sequences and HEREDOC Problem

Posted: Thu Aug 09, 2007 11:34 am
by iash
I'm new to PHP and I recently installed the xampp installer on my computer (includes PHP Ver. 5.2.3) and noticed that only some of the escape sequences work while other don't.

I have found that the following escape sequences don't work on my machine:

\n
\r
\t

However...the \\ , \$ , \" , octal and hex notation sequences work. In addition, the HEREDOC does not work on my computer either.

The following is an example of my test.php code followed by the output:

Code

<?php

echo "I purchsed the \"best\" burger on the planet \n for only \$2 \r while my fried \t Eric\\Erico sat on my chair"."<br>";

$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

print $str;

?>

Output

I purchsed the "best" burger on the planet for only $2 while my fried Eric\Erico sat on my chair
Example of string spanning multiple lines using heredoc syntax.

If you know how to fix this problem please help.....

Thanks
Isaac.

Posted: Thu Aug 09, 2007 11:59 am
by TheMoose
Those 3 escape sequences WILL NOT show up in a HTML rendered view. If you view the source of your page, you should see a tab, and newlines in that view. HTML does not render line breaks/tabs unless specified the pre/br tags.

Re: Escape Sequences and HEREDOC Problem

Posted: Thu Aug 09, 2007 12:06 pm
by superdezign
iash wrote:I have found that the following escape sequences don't work on my machine [...] In addition, the HEREDOC does not work on my computer either.
You assume too much. Try to view source or use nl2br().
All whitespace in HTML is rendered as one space. Otherwise, we wouldn't be able to format our HTML with tabbing.