I know when saving a textarea you can use the nl2br() or str_replace to change the /n to br tags etc. However what im not sure about how to insert line breaks into a textarea. I cant seem to find much about putting the data back into a textarea with those line breaks.
For example I have a form where users can update fields. So the user may enter:
foo
bar
baz
When that is saved to the database it would be saved as:
foo<br />bar<br />baz<br />
Now when that user goes back to that form after a page refresh all the fields are automatically populated with their previous data by taking the data from the database.
However the textarea shows the br tags as text instead of adding in the line breaks. i also tried changing the br tags to /n hoping the textarea would interpret these as line breaks but no joy. As well as this I also tried escaping etc.
So my questions are can this be done? Or more importantly can it be done using HTML/PHP (im using smarty). If that isnt possible can it be done using javascript?
Examples would be appreciated.
thanks for reading
question from:
https://stackoverflow.com/questions/6480655/line-breaks-in-a-textarea 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…