Jump to content

How to restore text format when reading a message out from database ?


tmyonline

Recommended Posts

Hi guys: 

 

My original message contains some specific format, such as some words are bold, others are italics.  Also, the message contains several paragraphs,... 

 

I had this message saved to MySQL.  By the time I retrieve this message, the format is lost, i.e., the words that are supposed to be bold are no longer bold (same problem with italics).  More seriously, all the paragraphs are somehow combined into one big paragraph.  How should I resolve this issue ?  I appreciate your help.  Thanks.

Well, how are they being rendered as bold? Are you using some html tags? BB tags? Or what?

 

As for apparent loss of new lines, you should use the nl2br() function on that kind of data being output for a web browser - it'll turn your new lines into <br > tags for the browser.

To get the paragraph and line breaks to dispay correctly.......

 


// Retrieve all the data from the table
$result = mysql_query("SELECT * FROM your_table") 
or die(mysql_error()); 

// store the record of the table into $row          
$row= mysql_fetch_array( $result );

$text = nl2br($row[text]);

echo "$text";

 

The line breaks and paragraphs are in your db, eeven though you can't see them.... nl2br will recover them. I'm in a rush so I can't get into your other formatting issues, but I'll check back later

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.