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'"); ?> Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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.