PDA

View Full Version : Storing html text?


mat
04-01-2004, 11:07 AM
I'm going to be populating a database table with around 30,000 records. Each record corresponds to a book. One of the columns holds the description (generally around 2-4 paragraphs).

This description text may have quotes, other funny characters and of course paragraph breaks. Correct me if I'm wrong but for these characters and paragraphs to display correctly on a web page the appropriate html codes/tags need to be there.

I can either store the html codes/tags in the table field so it's ready to pull out and display or I can store it as normal text with '\l' etc and parse it into html with PHP when I pull it out.

In terms of best practice, what do you suggest?

raf
04-01-2004, 12:46 PM
I can either store the html codes/tags in the table field so it's ready to pull out and display or I can store it as normal text with '\l' etc and parse it into html with PHP when I pull it out.

In terms of best practice, what do you suggest?

Depends on where you get the content from and the ratio of how many times it is changed/requested.
If you never or very sporadically change the content, then it should be ready to be outputted instantly. Like

echo $row['book_description'];

if you need to integrate it with other content and need to replace some placholders with actual values etc, then i store the PHP code inthere and eval it. Like

echo eval(stripslashes($row['book_description']));

the cellvalue can then look like

echo (\'<p>someblablla <a href="bla.php?id=\' . $theid . \'" title="bbf">New book</a> sdffdssdffds </p> ...\');

which was created using an addslashes() around the value in the insertstatement.

but i would always store it as html code (pure html or inside an echo()) to avoid converting it from plain text into html at runtime.