RKh
RKh

Reputation: 14161

[PHP/MySQL]: Is there a way to store text in Rich Text Format in MySQL table?

I have given en Entry Form to the user to input values that are stored in a MySQL table. There is one column called "Project Details", wherein the user can input upto 200 characters and this column is of type "varchar".

Till here everything is fine. The problem starts when the project details contain a number of points that are to be listed on the HTML page as:

(1) .........
(2) .........
(3) .........

It is unsure whether the project details is of one line, one paragraph, a simple text or a numbered list.

Is there any way to save the project details in rich text format in the MySQL table and when PHP shows the page of my website, the text gets listed as it was pasted?

Upvotes: 2

Views: 21100

Answers (5)

Terry
Terry

Reputation: 21

I encrypt using base64_encode() and to get I use base64_decode(). Tabs, spaces and special characters are preserved.

$statement->execute(array(':cemail' => $c_email,
':ctel' => $c_tel, ':msg' => base64_encode($c_msg)));

$msg = $rd['texe;];
$msg = base64_decode($msg)

Works perfectly for me

Upvotes: 1

Davide Gualano
Davide Gualano

Reputation: 13003

RTF is not the correct way to go because it's not interpreted correctly by webbrowsers.
You should use some markup language like Markdown, the one used here.

Upvotes: 0

Bartek
Bartek

Reputation: 15609

If you want to store something like rich text format, you'll probably want to place it into a BLOB field: http://dev.mysql.com/doc/refman/5.0/en/blob.html which has no actual character set assigned to it

Can I ask though, why you would want to do that? Why not use one of the many rich text editors that convert your information into HTML (like tinyMCE), which from there you can store as-is or pass it through a Html->Textile filter or something similar.

Upvotes: 5

schneck
schneck

Reputation: 10827

If you are really using RTF, you might need is RTF-to-HTML-Converter, a quick search brought this: http://directory.fsf.org/project/rtf2html/ (untested). Is this what you meant?

What kind of code you store in a MySQL-Database is up to you, but a Varchar is probably not the best field type; you should consider changing it into a Text-field.

Upvotes: 1

Paul Dixon
Paul Dixon

Reputation: 300855

You might want to consider using a simple markup language like Markdown or Textile. These allow you to take natural looking plain text, and then render it as HTML.

Failing that, you could simply display the text verbatim within <pre> tags.

Upvotes: 3

Related Questions