Welcome to WebmasterWorld Guest from 18.104.22.168
Does any one knows how to retrieve or save "email text" into mysql database, exactly in the manner in which it was saved?
I have made a member's section, in my personal website. I am able to save and retrieve mails sent by a member to another member but when i print the email body... the text looses its format.
Well, with all the thing i know about programming, I think to get over this there should be some mysql command or the "Text box" which i use for writing the email body should automatically add "<BR>" behind the scene when the user hit enter button...
Well, this is all i can think.. I will really appreciate if some one explains me how to get over this issue.
Thank you from a novice programmer.
Browsers collapse white space, is this what you mean?
Text should be stored in mysql with the carriage/line returns intact. If you're printing to the browser, you can wrap it in <pre> tags or substitute \n\r for <br> when you read from the database.
$msg = '<pre>' . $msg . '</pre>';
That gives you a monospaced font, usually courier, if it's for admin view this is all that's needed. If you want to pretty it up, use PHP methods or preg, which I use simply because I've been using regular expressions for years and am almost getting good at them. :-)
Hey man. How\'s it going.
This is just a test.
Did you see that video? Oh
you missed it. It\'s gone now.
echo "<p>raw: $msg</p>";
$msg = preg_replace('/[\n\r]+/',"<br>",$msg);
echo "<p>replaced: $msg</p>";
Note that this doesn't address the blank line, you make have to split it on the line breaks in an array to get at that.
Edited to simplify pattern
I've been using regular expressions for years and am almost getting good at them. :-)
You could also use nl2br($msg); instead of the regex which should deal with blank lines.
What about CSS?
The only problem with <pre> is that extremely long lines won't wrap.
So what you are saying is we all have something to look forward to in our old age ;)
Ayyy . . . . who you callin' old?
Yeah . . . I am . . . lol . . . the really bad part is, I can actually say I've forgotten more than many people know, and this is not a "brag," and it's not a good thing . . . .