Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2005, 05:42 PM
Authorized User
 
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default echo "\n" problem

I am a beginner of php. A simple question here is why echo "\n" doesn't work in my enviornment? I installed apachy2 php5 in windows xp system.
Anybody can let me know?
Thank you in advance,
Jun


 
Old November 28th, 2005, 09:25 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Can you be more specific? What happens when you do it? Do you see the PHP source? Also, you know you're only outputting a newline character, so you woulnd't be able to see it except when viewing source in the browser.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old November 29th, 2005, 11:16 AM
Authorized User
 
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rich,

Thank you for your reply.

So far as i know \n should print following characters in a new line, but if I type something like
echo "try \\n as change line \n to see if \n worked or not\n<br>";
the output in my IE browser is
try \n as change line to see if worked or not

At the same time, i noticed that \n works if put php code within <pre></pre> tag.

I guess I should do something in php.ini or some where else to allow html accept \n.

Do you have any idea?

Thanks,
Jun

 
Old November 29th, 2005, 11:33 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

That isn't PHP that's misbehaving. Newline characters are not rendered as line breaks by your browser. That's why you see line breaks when the <pre> tag is used. For that you want the PHP function nl2br() (new line to break).

Try this:

echo nl2br("try \\n as change line \n to see if \n worked or not\n");

http://www.php.net/nl2br

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old November 29th, 2005, 01:01 PM
Authorized User
 
Join Date: Nov 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Beautiful! Thank you very much Rich,Jun






Similar Threads
Thread Thread Starter Forum Replies Last Post
search data echo urbanaccess Access 7 January 23rd, 2007 10:54 AM
I need a echo wizard Anne1 PHP How-To 1 December 16th, 2006 04:20 AM
echo "\n" problem jun99 Beginning PHP 0 November 27th, 2005 05:12 PM
Problem with echo from query result Steve Newbie MySQL 2 August 16th, 2004 11:48 AM
using echo command to display "$" Tachyon PHP How-To 3 March 1st, 2004 09:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.