470,855 Members | 1,227 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Windows PHP 5.2.6 - Problems with Escape Characters

Hi,

I'm new to PHP and I am working through tutorials. I am running PHP
5.2.6, on windows xp. I am having problem with escape characters, they
do not seem to work. The below code example should display on multiple
lines, it just displays on 1 line no '\n' line breaks, it's ignored.
Is there something I need to set in the php.ini file? The php seems to
be installed fine as I can call functions etc.

<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);

echo "$newtext\n";
?>
Thanks

Ned
Jun 2 '08 #1
3 1417
sc****@gmail.com a écrit :
The below code example should display on multiple
lines, it just displays on 1 line no '\n' line breaks, it's ignored.
Is there something I need to set in the php.ini file? The php seems to
be installed fine as I can call functions etc.

<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);

echo "$newtext\n";
?>
Are you trying it through your browser ? Cause then, it displays as
expected in the source code only, while your browser doesn't handle
newlines and display all lines concatenated.
You can easily change it by echoing nl2br("{$newtext}\n"); (I prefer
using curly brackets into double-quoted strings)

Regards,
--
Guillaume
Jun 2 '08 #2
sc****@gmail.com wrote:
Hi,

I'm new to PHP and I am working through tutorials. I am running PHP
5.2.6, on windows xp. I am having problem with escape characters, they
do not seem to work. The below code example should display on multiple
lines, it just displays on 1 line no '\n' line breaks, it's ignored.
Is there something I need to set in the php.ini file? The php seems to
be installed fine as I can call functions etc.

<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);

echo "$newtext\n";
?>
Thanks

Ned

try

echo "<pre>$newtext\n</pre>";

browsers may not treat \n as <brunless it is within the <pretags.
Jun 2 '08 #3
Thank you all very much.

Yep I was testing through the browser, your suggetions worked.

Thanks again.

Jun 2 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Guadala Harry | last post: by
12 posts views Thread by Onega | last post: by
3 posts views Thread by Guadala Harry | last post: by
53 posts views Thread by noahmd | last post: by
131 posts views Thread by Lawrence D'Oliveiro | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.