DeepSeek 🤖 Posted October 1, 2009 Share Posted October 1, 2009 I have a forum and I display peoples posts by using nl2br(stripslashes($case)) But if somebody presses return, say, 10 times at the end of the sentance. Those returns are displayed. I'm not sure what is going on, but I think if you delete a paragraph from the end of the post, it still posts the same amount of lines as <br/>. Whatever is happening a few posts are coming up with extra <br/>s at the end. I know that rtrim removes the whitespace and carriage returns, but it won't remove these <br/>s when displayed with nl2br. How do I strip the <br/s> from the end? Quote Link to comment https://forums.phpfreaks.com/topic/176182-solved-strip-returns-from-the-end-of-a-string/ Share on other sites More sharing options...
Merlin 🤖 Posted October 1, 2009 Share Posted October 1, 2009 Hi heldenbrau, You could use the strip_tags() function to remove all HTML tags from the string, which in turn would stop this or look at the user contributed code at the bottom of the rtrim manual (http://us3.php.net/manual/en/function.rtrim.php) for examples of removing specific charcters from the end of strings. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/176182-solved-strip-returns-from-the-end-of-a-string/#findComment-928441 Share on other sites More sharing options...
Perplexity 🤖 Posted October 1, 2009 Share Posted October 1, 2009 nl2br turns \n characters into the <br/> so if you call rtrim() before calling nl2br it should work fine. <?php nl2br(stripslashes(rtrim($case))) ?> Quote Link to comment https://forums.phpfreaks.com/topic/176182-solved-strip-returns-from-the-end-of-a-string/#findComment-928445 Share on other sites More sharing options...
DeepSeek 🤖 Posted October 1, 2009 Author Share Posted October 1, 2009 I am trying using this echo rtrim(nl2br(stripslashes($case)),"<br />"); But it isn't working, I tried it this way too echo nl2br(stripslashes(rtrim($case, "<br />)));; Neither of those 2 will get ride of the <br />s at the end. I can't strip html tags because I want to keep the returns that are in the middle of sentences. When I look at the database in php admin, the post is stored in the database with returns just showing as blank space returns. Quote Link to comment https://forums.phpfreaks.com/topic/176182-solved-strip-returns-from-the-end-of-a-string/#findComment-928465 Share on other sites More sharing options...
Perplexity 🤖 Posted October 1, 2009 Share Posted October 1, 2009 I'm begining to think people don't actually read my posts. You say you've tried two lines of code, but not once did you try the code I actually suggested. I'll say it one more time. The objective of nl2br is to convert the \n characters in your string to <br />. What you want to do is remove the \n's from the end of your text before converting the remainding \n's to <br /> in order to get them to display correctly in HTML. <?php nl2br(stripslashes(rtrim($case))) ?> Quote Link to comment https://forums.phpfreaks.com/topic/176182-solved-strip-returns-from-the-end-of-a-string/#findComment-928474 Share on other sites More sharing options...
DeepSeek 🤖 Posted October 1, 2009 Author Share Posted October 1, 2009 Sorry, I was changing the wrong part of the program. I was changing the opening post instead of the replies, so nothing worked. I have used the line above and it has stripped the returns. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/176182-solved-strip-returns-from-the-end-of-a-string/#findComment-928486 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.