Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2005, 05:42 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old November 28th, 2005, 09:25 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
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
Reply With Quote
  #3 (permalink)  
Old November 29th, 2005, 11:16 AM
Authorized User
 
Join Date: Nov 2005
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old November 29th, 2005, 11:33 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
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
Reply With Quote
  #5 (permalink)  
Old November 29th, 2005, 01:01 PM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Beautiful! Thank you very much Rich,Jun

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.