nemesis.2002 Posted October 27, 2008 Share Posted October 27, 2008 So i'm making a php website, this is actually my first php site this complex. But i've run into a snag. My client updates his website trough a admin page that sends all the info to a mysql database but it dosen't save the format on the way he typed it in. For example: if he presses enter twice in a row in the textarea form he wants it to go to the next line and skip a line, but what ends up happening it displays in one line. Is their a way to do this in php? So that an "enter" key stroke will generate a <br> tag or something? Link to comment https://forums.phpfreaks.com/topic/130291-solved-saving-format-of-text-to-database/ Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 Try using the nl2br function, you need to use it during the output, normally preformatting it will not work but when you use it at the output it should work fine. $string_from_db = 'Your text from database'; echo nl2br($string_from_db); Link to comment https://forums.phpfreaks.com/topic/130291-solved-saving-format-of-text-to-database/#findComment-675704 Share on other sites More sharing options...
nemesis.2002 Posted October 27, 2008 Author Share Posted October 27, 2008 So if $text_from database is what i bring out from mysql i should do this $query = "SELECT * FROM text_fill "; $mysql_stuff = mysql_query($query, $mysql_link); while($row = mysql_fetch_row($mysql_stuff)) { $id = $row[0]; $$text_from database = $row[14]; $string_from_db = $text_from database; echo nl2br($string_from_db); print("$string_from_db"); } and that should format it properly? Link to comment https://forums.phpfreaks.com/topic/130291-solved-saving-format-of-text-to-database/#findComment-675711 Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 Try this: <?php $query = "SELECT * FROM text_fill "; $mysql_stuff = mysql_query($query, $mysql_link); while($row = mysql_fetch_row($mysql_stuff)) { $id = $row[0]; $$text_from database = $row[14]; $string_from_db = $text_from database; echo nl2br($string_from_db); } ?> Both print and echo will output the text. I just removed the print line. Also, what format is the text stored in the database? Is it Varchar, text? Link to comment https://forums.phpfreaks.com/topic/130291-solved-saving-format-of-text-to-database/#findComment-675712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.