[Solved by astions] Escape sequences [/Solved]

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
LordJonsson
Forum Newbie
Posts: 3
Joined: Tue Sep 26, 2006 12:19 am

[Solved by astions] Escape sequences [/Solved]

Post by LordJonsson »

How can I get Escape sequences to work in my code?
Using:
PHP 5.2.0RC5-dev
Apache/2.2.3

php:

Code: Select all

<?php
	echo "a\nb";
?>
Result:
a b

But I want the result to be:
a
b

And i'm sorry if i'm one of thousans and thousands of people hwo asked this question on this forum.
Thx in advance.
Last edited by LordJonsson on Tue Sep 26, 2006 12:58 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Browsers don't render new lines. You need an <br /> in there.

Code: Select all

echo nl2br("a\nb");
LordJonsson
Forum Newbie
Posts: 3
Joined: Tue Sep 26, 2006 12:19 am

Post by LordJonsson »

ohh c'mon so i'll always have to include nl2br("");?
What about if I want to put tab \t?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Browsers don't render multiple spaces either. Not sure about tabs so you might just want to test it.

Your other option is to do this..

Code: Select all

<pre>
<?php echo "this will render on\n2 lines"; ?>
</pre>
LordJonsson
Forum Newbie
Posts: 3
Joined: Tue Sep 26, 2006 12:19 am

Post by LordJonsson »

Thx alot, if I put <pre> over all of my code the escape sequences work!
Post Reply