I have a system that allows users to add an article to a mysql database by inputting the article into a textbox and then simply inserting it into the database. The problem (as you probably already know) is that when you go to select (display) that same article from the database it is no longer formatted with line breaks. I don't want my users to have to know to input a <br /> tag every time they want a line break.
The PRE tag just leads to mayhem since it is highly unreliable. Is there any other way to make sure that the article has the same line breaks (when displayed from the database) as when the user inputed it.
I am open to any method required to get this done. Thanks in advance!
Any alternatives to using <pre> when displaying db text?
Moderator: General Moderators
Re: Any alternatives to using <pre> when displaying db text?
Look on function nl2br() (Inserts HTML line breaks before all newlines in a string)
Or use something like this str_replace("\n", "<br> ", $str);
Or use something like this str_replace("\n", "<br> ", $str);
Re: Any alternatives to using <pre> when displaying db text?
Thank you! This is perfect, and so simple...wow, never would have guessed...