lukelee Posted December 10, 2008 Share Posted December 10, 2008 I am making a simple cms, i enter the text in a textarea,then save into sql something like: test123 test456 but it display the contents in one line, like: test123test456 does anyone know how to make sql save the 'enter'? thanks here is my codes: <form name="service" method="post" action="service_update.php"> <textarea name="content"></textarea> <input type="submit" name="submit" id="submit" value="Submit" /> </form> <?php session_start(); require_once('db.php'); $content = $_POST["content"]; $result=mysql_query("UPDATE content SET content='$content' WHERE id='6'"); ?> Link to comment https://forums.phpfreaks.com/topic/136315-sql-doesnt-save-enter-which-i-entered-in-a-textarea/ Share on other sites More sharing options...
haku Posted December 10, 2008 Share Posted December 10, 2008 http://jp2.php.net/manual/en/function.nl2br.php Link to comment https://forums.phpfreaks.com/topic/136315-sql-doesnt-save-enter-which-i-entered-in-a-textarea/#findComment-711151 Share on other sites More sharing options...
lukelee Posted December 10, 2008 Author Share Posted December 10, 2008 http://jp2.php.net/manual/en/function.nl2br.php I read that, but I dont understand, how do i put those codes into my codes? Link to comment https://forums.phpfreaks.com/topic/136315-sql-doesnt-save-enter-which-i-entered-in-a-textarea/#findComment-711213 Share on other sites More sharing options...
lukelee Posted December 10, 2008 Author Share Posted December 10, 2008 I have done half of it: <?php $query = mysql_query("SELECT content FROM content Where id='6'"); while($row = mysql_fetch_array($query)) { $content = $row['content']; function format_html($content) { $content = "<p>" . str_replace("\r\n", "<br/>", $content) . ""; $content = "" . str_replace("<br/><br/>", "</p><p>", $content) . ""; return "" . str_replace("<br/><li>", "<li>", $content) . ""; } echo format_html("$content"); }?> it works on 'enter' change a new line, but still not work if i want to have more spaces between words.like: 123 456 it only display 1 space: 123 456 does anyone know what code do i have to add? Link to comment https://forums.phpfreaks.com/topic/136315-sql-doesnt-save-enter-which-i-entered-in-a-textarea/#findComment-711243 Share on other sites More sharing options...
Mchl Posted December 10, 2008 Share Posted December 10, 2008 This has nothing to do with PHP, but with HTML. HTML will trim all your spaces to one, and will ignore all line breaks. (Well...not HTML, but browser parsing it actually) You have to put your content within <pre> </pre> tags to keep these whitespace characters displayed. Link to comment https://forums.phpfreaks.com/topic/136315-sql-doesnt-save-enter-which-i-entered-in-a-textarea/#findComment-711244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.