?
Solved

\n problem

Posted on 2002-07-11
9
Medium Priority
?
196 Views
Last Modified: 2006-11-17
Can somebody explain to me why php doesn't replace \n with a linefeed?  When I print text that contains \n, the whole string appears on the same line and all the \n are visible. Why?
0
Comment
Question by:huxun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 

Author Comment

by:huxun
ID: 7145989
Multiple post ... please delete!
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7146105
Something to be aware of (you may already know), if you want to show html on several lines and you are using \n to terminate lines, you can use the nl2br function to put in <br> instead of \n.

Regards,

Richard Quadling.
0
 
LVL 2

Expert Comment

by:egomaster
ID: 7146266
I recall having a similar problem that is having \n being printed instead of being line feeds.
Can you please post your PHP code and I might remember what was wrong.
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

Author Comment

by:huxun
ID: 7146282
I have already solved this problem with help from some experts on another thread.  As I explained, this is a multiple post, due to a refresh. I really think that bug should be fixed.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7146309
<html>
<body>
<?php

echo 'This is on line 1.\nThis is on line 2.\n';

echo "This is on line 3.\nThis is on line 4.\n";

echo nl2br('This is on line 5.\nThis is on line 6.\n');

echo nl2br("This is on line 7.\nThis is on line 8.\n");

?>
</body>
</html>

produces (via View Source)

<html>
<body>
This is on line 1.\nThis is on line 2.\nThis is on line 3.
This is on line 4.
This is on line 5.\nThis is on line 6.\nThis is on line 7.<br />
This is on line 8.<br />
</body>
</html>

which renders to ...

This is on line 1.\nThis is on line 2.\nThis is on line 3. This is on line 4. This is on line 5.\nThis is on line 6.\nThis is on line 7.
This is on line 8.

Only line 8 is actually on a seperate line.

Regards,

Richard.
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 100 total points
ID: 7146317
The answer here is if you want breaks in both the code and in the rendered output, you need ...


nl2br("\n");



Regards,

Richard.
0
 

Author Comment

by:huxun
ID: 7146322
WTF!!!
0
 

Author Comment

by:huxun
ID: 7146335
I'll give you the points, you deserve them. Don't spend them all at once.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7146337
Thanks!
0

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question