Page 1 of 1
What could you use for br2nl?
Posted: Wed Oct 23, 2002 10:50 am
by sinewave
i know there isnt a br2nl() but i have a textarea that reads and writes to a txtfile, but when i use nl2br() to put the breaks in the txt, that's fine.
When i read from the txtfile it will put the "<br />" back into the textarea (obviously), but i'd prefer it put new lines there. The people who will use the text area to update certain sections will know no html. Any advice would be great.
Posted: Wed Oct 23, 2002 11:00 am
by twigletmac
You shouldn't need to do nl2br() unless you are about to display the data (outside of a textarea) as nl2br() just puts <br />'s next to newline characters - it doesn't replace one with the other. So, in your text file just store the text with only the newline characters, you don't need to store both.
However, getting rid of the stored <br />'s is nice and easy thanks to
str_replace():
Code: Select all
$text = str_replace('<br />', '', $text);
Mac
Posted: Wed Oct 23, 2002 11:06 am
by sinewave
well teh textarea goes to a txt file, and then another page uses the txtfile to display it's contents in html. so if they press enter 5 times i want it to put 5 <br />, i dont know how else you could do that without nl2br()
but also i want it to go backwards too...if the txtfile has <br /> 5 times i want the text area to have 5 line breaks
does this make sense?
could you str_replace with \n or something to that effect?
Posted: Wed Oct 23, 2002 12:08 pm
by superwormy
$string = str_replace ("<br />", "\n", $string);
Posted: Wed Oct 23, 2002 2:12 pm
by twigletmac
Using nl2br() does not remove the newline characters it only puts the HTML line break next to it so if you had
after using nl2br() you would have
so to get rid of the HTML line breaks use the code I showed before:
Code: Select all
$text = str_replace('<br />', '', $text);
and you'll have
again. If you use superwormy's code you'll end up with double newline characters:
Mac
Posted: Wed Oct 23, 2002 4:56 pm
by sinewave
perfect. thanks