views:

138

answers:

2

I have wrote a simple php script which reads an IMAP email account and displays the body of the most recent mail. There is just one problem, it won't keep the new lines properly. It just puts it all on one line.

I use

imap_fetchbody($conn, $latest, "1");

to read the body of the email. How do I keep the original formatting with all the proper line breaks. Much thanks

+3  A: 

Are you outputting to a browser? Try using nl2br. The doc says:

Inserts HTML line breaks before all newlines in a string

Example:

<?php
echo nl2br("foo isn't\n bar");
//output: foo isn't<br /> bar
?>
karim79
@karim79 - I never knew about this function and have made one to convert it myself. I guess you learn something every day.
Buggabill
@Buggabill - true, I suppose it doesn't help that PHP has about 500,000,000 functions.
karim79
wow, had no idea this existed. It is extremely handy. Thanks again
Steven1350
A: 

Why don't you try the print_r option which is in built in PHP?

Supriya