[SOLVED] Printing data from mysql field and retaining format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

Printing data from mysql field and retaining formatting

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

carraige returns would be [php_man]nl2br[/php_man]().
spacing should be retained
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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  
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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.
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

Post by clem_c_rock »

Thanks,

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

Thanks!
Post Reply