spiceydog Posted November 28, 2008 Share Posted November 28, 2008 I'm sure there's an easy way around this but I have some forums that I made and I want users to be able to organize there posts with line breaks but I still do want want to give them the power to post html in there posts. Currently I have the posting setup so when you post it runs an nl2br on the post and then when it echos the post it does a str_replace("<br />", "\r", $post) but that doesn't work. i hope that makes sense. im really bad with the wording that scripters use lol. Quote Link to comment https://forums.phpfreaks.com/topic/134658-solved-htmlentities-not-showing-hard-returnsline-breaks/ Share on other sites More sharing options...
flyhoney Posted November 28, 2008 Share Posted November 28, 2008 Do you mean... but I still do NOT want want to give them the power to post html in there posts. If so, there is no real way to add space to text on a web page without using HTML. You could use a crap ton of Quote Link to comment https://forums.phpfreaks.com/topic/134658-solved-htmlentities-not-showing-hard-returnsline-breaks/#findComment-701208 Share on other sites More sharing options...
wildteen88 Posted November 28, 2008 Share Posted November 28, 2008 Currently I have the posting setup so when you post it runs an nl2br on the post ... nl2br converts new lines to <br /> for you. Use nl2br when you're getting data out of the database. Not when you are inserting it into the database. I don't Understand what you mean by ... and then when it echos the post it does a str_replace("<br />", "\r", $post) but that doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/134658-solved-htmlentities-not-showing-hard-returnsline-breaks/#findComment-701328 Share on other sites More sharing options...
spiceydog Posted November 28, 2008 Author Share Posted November 28, 2008 well how do these forums do it? i can put double line breaks between each line like this but if i try to fill this post with html it wont work. Quote Link to comment https://forums.phpfreaks.com/topic/134658-solved-htmlentities-not-showing-hard-returnsline-breaks/#findComment-701351 Share on other sites More sharing options...
DeanWhitehouse Posted November 29, 2008 Share Posted November 29, 2008 nl2br(); when you are reading from a database, or just displaying anything from a textarea. Quote Link to comment https://forums.phpfreaks.com/topic/134658-solved-htmlentities-not-showing-hard-returnsline-breaks/#findComment-701383 Share on other sites More sharing options...
ShiloVir Posted November 29, 2008 Share Posted November 29, 2008 or to make things really complicated. wouldnt this not work? <?php // Function: function nls2p($str) { return str_replace('<p></p>', '', '<p>' . preg_replace('#([\r\n]\s*?[\r\n]){2,}#', '</p>$0<p>', $str) . '</p>'); } // In Context: <?php echo nl2br(nls2p("Paragraph1\n\nParagraph2\n line1\n line2\n")); ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/134658-solved-htmlentities-not-showing-hard-returnsline-breaks/#findComment-701460 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.