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.
What could you use for br2nl?
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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():
Mac
However, getting rid of the stored <br />'s is nice and easy thanks to str_replace():
Code: Select all
$text = str_replace('<br />', '', $text);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?
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?
-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
and you'll have
again. If you use superwormy's code you'll end up with double newline characters:
Mac
Code: Select all
line1 \n line2Code: Select all
line 1 <br />\n line2Code: Select all
$text = str_replace('<br />', '', $text);Code: Select all
line 1 \n line2Code: Select all
line1 \n\n line2