Escape Sequences and HEREDOC Problem

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
iash
Forum Newbie
Posts: 1
Joined: Thu Aug 09, 2007 11:09 am

Escape Sequences and HEREDOC Problem

Post 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.
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Escape Sequences and HEREDOC Problem

Post 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.
Post Reply