PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 8th, 2003, 05:40 PM
eqjones eqjones is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: South Carolina
Posts: 18 eqjones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Formatting a newline/line break in PHP/HTML output

I'm writing some php stuff and want to check the html output. But it's all written on one line. I've seen in tutorials here where the authors were using something to format the html output of the php so it comes out all neat.

I've tried /n and \n but they aren't working. So my question is how to I get php to format the html output so I can add line breaks into the html output?\

Thanks!

Reply With Quote
  #2  
Old October 8th, 2003, 11:12 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 8
\n should do the trick.

if you are trying to output a textarea, then use nl2br();
__________________
-- Jason

Reply With Quote
  #3  
Old October 9th, 2003, 02:35 PM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 7
When you are echoing \n remember that it will need parsing so it should be coded as follows:
PHP Code:
echo "a\nb";
// would output a then newline then b

// another example
echo '<html>' "\n";
echo 
'<head>' "\n" '<title>';
// etc 


Let us know how you do

Reply With Quote
  #4  
Old October 11th, 2003, 09:17 PM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Just as Taelo said...

Use:

echo nl2br($yourTextData);


Just do this when showing your data as HTML.

__________________
The deal is not to know everything, but to know the email of the one who does.

Reply With Quote
  #5  
Old November 7th, 2007, 02:33 PM
stephen.bigelis stephen.bigelis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 2 stephen.bigelis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 13 sec
Reputation Power: 0
Php_eol

If you are trying to format your HTML source, you should use the constant PHP_EOL. The main reason being that on windows machines the EOL is \r\n and on UNIX machines it is \n. With a properly installed LAMP set up just use PHP_EOL like so.

$html.="<p>This is my HTML</p>" . PHP_EOL;

cheers,
_Stephen

Reply With Quote
  #6  
Old November 19th, 2007, 06:15 PM
datahound datahound is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 1 datahound User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 26 sec
Reputation Power: 0
Quote:
Originally Posted by stephen.bigelis
If you are trying to format your HTML source, you should use the constant PHP_EOL. The main reason being that on windows machines the EOL is \r\n and on UNIX machines it is \n. With a properly installed LAMP set up just use PHP_EOL like so.

$html.="<p>This is my HTML</p>" . PHP_EOL;

cheers,
_Stephen


Thanks that was exactly what I needed to output into a javascript array.

do {
$docount = $docount + 1;
echo "'stockthumbs/$pic_array[$docount]',". PHP_EOL;
} while ($docount < $count-1);
$docount = $docount + 1;
echo "'stockthumbs/$pic_array[$docount]'". PHP_EOL;

Reply With Quote
  #7  
Old September 4th, 2009, 11:44 AM
organicflash organicflash is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 1 organicflash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 33 sec
Reputation Power: 0
This comment saved me from a very perplexing problem in Outlook 2007. PHP generated HTML emails would break in a rather random way. What seemed to be happening was that Outlook did not like receiving the HTML as one long unbroken string. So, it would take the liberty of breaking it after a certain point. That might be in the middle of an html tag and break the tag. Thus the html email would not display correctly.

It appears to happen with very long php generated HTML emails.

In any case, adding the . PHP_EOL; tag every once in a while solved the problem.

like so:

body .= "<br>" . PHP_EOL;

This is an old thread, but I wanted to re-open it in case it might help someone struggling with this problem as much as me.

Kurt


Quote:
Originally Posted by stephen.bigelis
If you are trying to format your HTML source, you should use the constant PHP_EOL. The main reason being that on windows machines the EOL is \r\n and on UNIX machines it is \n. With a properly installed LAMP set up just use PHP_EOL like so.

$html.="<p>This is my HTML</p>" . PHP_EOL;

cheers,
_Stephen

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Formatting a newline/line break in PHP/HTML output


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek