Jump to content

[SOLVED] Strip returns from the end of a string.


heldenbrau

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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))) 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.