I
I
IvanIF2020-08-23 19:08:00
Database design
IvanIF, 2020-08-23 19:08:00

What is the best way to store articles for a website in a database?

Let's assume that there is a thematic portal where users can publish articles. Articles will be written in textarea, where it will be possible to insert various additions (citations, lists, images, etc.). Here is an example of inserting an add-on:

To insert an image, the user must add this code: And on the server it will be replaced with something like this:

<img src="НОМЕР ИЗОБРАЖЕНИЯ" title="ОПИСАНИЕ" />


<div class="img-block">
   <img src="НОМЕР ИЗОБРАЖЕНИЯ" />
   <p>ОПИСАНИЕ</p>
</div>


How in this case is it better to store articles for the site in the database? It turns out there is text written by the user (let's call it text 0 ) and text converted on the server (let's call it text 1 ). How to store all this stuff in the database? Is it better to store only text 0 , and on page load convert everything to text 1 ? Or keep both options? Text 0 is needed in any case, because if the user wants to edit the article, then I will upload it to the textarea. I read a lot of opinions that tags cannot be stored in the database, and also that popular CMS systems do just that. All in all, I'm confused. Please advise the correct option.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
necrodeflorator, 2020-08-23
@IvanIF

Yes, you are basically correct.
You will parse the source text, look for key structures in it? It's easier to do this once when saving the article and output the finished html.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question