[web] PHP nl2br textarea problem

Started by
1 comment, last by password 17 years, 8 months ago
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.
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".
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.

This topic is closed to new replies.

Advertisement