Connecting Tech Pros Worldwide Forums | Help | Site Map

How to format text retrieved from an MSQL Database

Newbie
 
Join Date: Aug 2007
Posts: 2
#1: Aug 6 '07
I have an application that writes text to a MySQL data base from an HTML form. The text in the MySQL table retains the formatting in the form (line breaks etc.) However when I retrieve the text and display it in an HTML layer all the formatting is gone.

Is there any way PHP can retrieve the formatting from the database?There's no way I can write code to do the formatting because I don't know how it was originally entered.

jx2 jx2 is offline
Familiar Sight
 
Join Date: Feb 2007
Location: Bristol UK
Posts: 227
#2: Aug 6 '07

re: How to format text retrieved from an MSQL Database


i think u need this

u might try wordwrap(); too

hope tht help
jx2
Newbie
 
Join Date: Aug 2007
Posts: 2
#3: Aug 7 '07

re: How to format text retrieved from an MSQL Database


Hi,

I found a solution;

<?php echo nl2br(str_replace(" ","&nbsp",stripslashes($row["textsum"]))); ?>

the nl2br function puts line breaks in and the str_replace puts the spaces back in.
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#4: Aug 7 '07

re: How to format text retrieved from an MSQL Database


Quote:

Originally Posted by charless

Hi,

I found a solution;

<?php echo nl2br(str_replace(" ","&nbsp",stripslashes($row["textsum"]))); ?>

the nl2br function puts line breaks in and the str_replace puts the spaces back in.

Glad you got it working. post back any time if you have any issues!
Reply