Displaying text from textarea. |
[eluser]donald.tbd[/eluser]
Hello, I have a problem displaying text i wrote into a textarea and saved into a database. For example i wrote: Hello my name is Donald Now if i just select it from database and echo it into a blank page i get "Hello my name is Donald" all in one row. If i echo it into a textarea i get the result i wrote, every word on seperate row. How can i get the same result on a blank page? Cheers!
[eluser]TWP Marketing[/eluser]
I found this in an old post from 2004 and modified it for your case. It 'should' still work with today's browsers... The html textarea will return some form of the newline tag to do linebreaks. It is browser specific, but there are only a limited number of choices. If this fails, check on the php function nl2br(). Code: <?php
[eluser]John_Betong_002[/eluser]
@TWP Marketing edit Whoops - I never noticed your reference to nl2br() http://php.net/manual/en/function.nl2br.php
[eluser]donald.tbd[/eluser]
Thanks, nl2br did the trick. Now the question is can i put it somewhere in the code so i dont have to write it in the view part every time i need to display a textarea content. Or is it better to write it in the view?
[eluser]John_Betong_002[/eluser]
[quote author="donald.tbd" date="1308284899"]Thanks, nl2br did the trick. Now the question is can i put it somewhere in the code so i dont have to write it in the view part every time i need to display a textarea content. Or is it better to write it in the view?[/quote] Try it and see if there is a difference between view, controller or model. Let us know if you have any problems. Usually I use nl2br() in the model. It is up to you where you use it. |
Welcome Guest, Not a member yet? Register Sign In |