HockeyDevil07 Posted September 12, 2008 Share Posted September 12, 2008 Hey everyone, I'm not sure if this is the right forum to post this in, but here it goes. I'm writing a web page with a simple message board for users to discuss a few topics. Everything works fine but when the message text is retrieved from MySQL and put back onto the page the return spaces aren't there. Here's what I mean: "This is the the message body. This is the second line. This is the third line." It shows up my MySQL database exactly as written up there, but when it is put onto the web page it'll show up like: "This is the message body. This is the second line. This is the third line." Obviously I want it to be displayed the way I intended it to be. I know why it's outputting it like that. I was wondering if anyone here could give me some hints on how to parse the message (not sure if that's really what I need to do) or if there are any simple fixes to this problem. Any links to information, tips, or suggestions are welcome. Thanks in advance for anyone's help! Quote Link to comment https://forums.phpfreaks.com/topic/123979-how-can-i-properly-display-my-text/ Share on other sites More sharing options...
pocobueno1388 Posted September 12, 2008 Share Posted September 12, 2008 You need to use the function nl2br() when displaying it. Quote Link to comment https://forums.phpfreaks.com/topic/123979-how-can-i-properly-display-my-text/#findComment-640017 Share on other sites More sharing options...
Stryves Posted September 12, 2008 Share Posted September 12, 2008 When you are displaying your page Let's say your Query variable is message3 to grab the body from the database, put this just before where you are going to display the body info $body=nl2br($message3[body]); Then print "$body"; Quote Link to comment https://forums.phpfreaks.com/topic/123979-how-can-i-properly-display-my-text/#findComment-640019 Share on other sites More sharing options...
HockeyDevil07 Posted September 12, 2008 Author Share Posted September 12, 2008 Success! wow guys thanks for such a fast response, you just made my day. Quote Link to comment https://forums.phpfreaks.com/topic/123979-how-can-i-properly-display-my-text/#findComment-640025 Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 By the way, just so you know: Inside textareas and files and all sorts of stuff, lines are determined by the presence of ASCII code 0x0A. This is represented in most programming languages as "\n" (the double quotes are required). This works great for files and storing the data, because it's just one character, but HTML doesn't treat whitespace literally, as you probably know. They use <br /> tags in order to enter line breaks. nl2br() just adds a <br /> before every "\n" in the string. The "\n" still remains there though. Quote Link to comment https://forums.phpfreaks.com/topic/123979-how-can-i-properly-display-my-text/#findComment-640031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.