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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.