EPCtech Posted September 12, 2008 Share Posted September 12, 2008 Hello, For some reason, nl2br() is making too many line breaks after being replaced. When creating blogs on my website, you experience a bad problem. I use nl2br when finishing the editing and str_replace so that the users don't see the "<br />" tags but in this process the number of line breaks doubles. Especially when editing my homepage and such (my homepage gathers data from a database for it's text; It doesn't use HTML for the text). Please help! Best Regards, En-Psyche Tech Link to comment https://forums.phpfreaks.com/topic/123864-nl2br-against-me/ Share on other sites More sharing options...
kenrbnsn Posted September 12, 2008 Share Posted September 12, 2008 Code? Without see what you're doing, it's hard for us to help. Ken Link to comment https://forums.phpfreaks.com/topic/123864-nl2br-against-me/#findComment-639509 Share on other sites More sharing options...
EPCtech Posted September 12, 2008 Author Share Posted September 12, 2008 Ok, sorry, I tend to think I can summarize my problem with words. It always fails. Now, this is when creating a page: $name=mysql_real_escape_string(stripslashes($_POST['name'])); $content=mysql_real_escape_string(nl2br($_POST['content'])); mysql_query("INSERT INTO pages (name,content) VALUES ('".$name."','".$content."')"); echo "Page created"; This is editing a page, before hitting submit: $page1=$_GET['page']; $sql=mysql_query("SELECT content FROM pages WHERE name='".$page1."'"); list($page)=mysql_fetch_array($sql); $page=str_replace("<br />","\n",$page); And this is editing after hitting submit: $page2=$_GET['page']; $content=mysql_real_escape_string(nl2br($_POST['content'])); mysql_query("UPDATE pages SET content='".$content."' WHERE name='".$page2."'"); echo "Page updated!"; When created, the page is like this: Hello. This is a test. Then I click edit, change nothing and hit submit. Hello. This is a test. Why does this happen? Link to comment https://forums.phpfreaks.com/topic/123864-nl2br-against-me/#findComment-639512 Share on other sites More sharing options...
kenrbnsn Posted September 12, 2008 Share Posted September 12, 2008 Do not use nl2br() when you store the data, only when you display the data. The function does not replace "\n" with a "<br />", it inserts the "<br />" next to the "\n", therefore you are adding an extra "\n" with your str_replace. Ken Link to comment https://forums.phpfreaks.com/topic/123864-nl2br-against-me/#findComment-639515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.