Page 1 of 1

Printing data from mysql field and retaining formatting

Posted: Tue Oct 19, 2004 10:26 am
by clem_c_rock
Hello,
I am saving data from a textarea field into a database. When I view the data in the mysql table, the spaces and formatting is retained, but when I try to print it out on a page, it just prints the info out as a continuous wrapped string w/ no formatting.

What can I do to retain the spaces and carriage returns?

Thanks,

Clem

Posted: Tue Oct 19, 2004 10:34 am
by phpScott
carraige returns would be [php_man]nl2br[/php_man]().
spacing should be retained

Posted: Tue Oct 19, 2004 10:35 am
by nigma
For your problem with new lines: [php_man]nl2br()[/php_man]
For your problem with spaces: Use regular expressions to replace all spaces with  

Posted: Tue Oct 19, 2004 10:36 am
by nigma
I think he means when you outputs the html the spaces don't show up? Which of course doesn't mean that the spaces aren't there, they just aren't showing up in the outputted html.

Posted: Tue Oct 19, 2004 11:30 am
by clem_c_rock
Thanks,

Actually, the line breaks where the main thing I was concerned about so the nl2br() function was perfect.

Thanks!