[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

\n problem

Posted on 2002-07-11
9
Medium Priority
?
200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 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