Sign in to follow this  

[web] PHP nl2br textarea problem

This topic is 4137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have made an article script which is using nl2br(), so each article automatically puts <br /> after each line. The problem now is that I have a textarea in the same article that is supposed to be able to show code. Everything works fine except that the <br /> tags are shown as text in the textarea. This would be no big deal in normal cases, but in this case I need to use something like strip_tags in the textarea only. I can't use strip_tags in the whole article, that will remove all the <br's>. I only want to remove them in the textarea. I guess I could make a function that removes all <br /> in the code that is sent in as a parameter but wouldn't that force me to send a line at a time as parameter? On a secound thought, that is impossible because the <br's> are hidden in the first place. Anyways do you have any ideas? thankful for help.

Share this post


Link to post
Share on other sites
Have you tried writing a conditional strictly for the <textarea>? It's hard for me to see exactly what's going on, but if you were to place the printed data into a variable, and if you know ahead of time when the textarea is called, this is more helpful. In the variable that contains the textarea, str_replace() any instance of <br /> (or
, whatever you have) with "\n".

Share this post


Link to post
Share on other sites
Now when you said it. I can always use substr to check if a <textarea> is in the text. If it is, replace every "<br />" between <textarea> and </textarea> with "" or something like that.

Share this post


Link to post
Share on other sites

This topic is 4137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this