Jump to content
  • Advertisement
Sign in to follow this  
password

[web] PHP nl2br textarea problem

This topic is 4350 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!