Page 1 of 1

[Solved by astions] Escape sequences [/Solved]

Posted: Tue Sep 26, 2006 12:27 am
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.

Posted: Tue Sep 26, 2006 12:30 am
by Benjamin
Browsers don't render new lines. You need an <br /> in there.

Code: Select all

echo nl2br("a\nb");

Posted: Tue Sep 26, 2006 12:41 am
by LordJonsson
ohh c'mon so i'll always have to include nl2br("");?
What about if I want to put tab \t?

Posted: Tue Sep 26, 2006 12:54 am
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>

Posted: Tue Sep 26, 2006 12:57 am
by LordJonsson
Thx alot, if I put <pre> over all of my code the escape sequences work!