简体   繁体   English

PHP MySQL自定义博客,格式发布

[英]PHP MySQL custom blog, formatting post

I'm creating my own blog in PHP and want to know your opinions on how I should format my post content. 我正在用PHP创建自己的博客,并想知道您对我应如何格式化帖子内容的意见。

Currently I store the post content as just plain text, call it when necessary, then wrap each line with P tags. 目前,我将帖子内容存储为纯文本,必要时调用它,然后用P标签包装每行。 I did this in case I wanted to change the way I formatted my text in the future and it would save me the dilema of having to remove all P tags from the posts in the DB. 我这样做是为了防止日后更改我格式化文本的方式,从而避免了我不得不从数据库中的帖子中删除所有P标签的麻烦。

Now the problem I have this this method is that if I want to add extra formatting in, eg lists etc those would also be wrapped with P tags which is not correct. 现在我有这种方法的问题是,如果我想在列表中添加额外的格式,例如列表等,也将被不正确的P标签包装。

How would you do this, would you store text as plain text in the DB, or would you add the HTML formatting and store that in the DB to? 您将如何执行此操作,将文本以纯文本格式存储在数据库中,还是添加HTML格式并将其存储在数据库中?

I'd prefer not to store unnessary HTML in the DB, but not sure of a way around it? 我不想不要在数据库中存储不必要的HTML,但是不确定是否可以解决?

I think the best way would be to keep the html in the db. 我认为最好的方法是将html保留在数据库中。 You would have too much to work with parsing the text if you don't use html. 如果您不使用html,那么解析文本将需要太多工作。

See how it's done in other blog tools. 在其他博客工具中查看完成情况。 I know that Joomla, for example, keeps all html in the db. 我知道,例如,Joomla将所有html保留在数据库中。 I know Joomla isn't blog tool :) but still... 我知道Joomla不是博客工具:),但仍然...

Wordpress stores html in the db. WordPress将html存储在数据库中。 You say you are concerned about storing 'unnecessary' html in the db. 您说您担心要在数据库中存储“不必要的” html。 What makes it unnecessary? 是什么使它不必要? I think it is the opposite. 我认为是相反的。 You may have headings or bold or italic text in your post. 您的帖子中可能包含标题,粗体或斜体文本。 If storing as plain text, how do you save this formatting? 如果以纯文本格式存储,如何保存这种格式? How are you saving the lists you mentioned? 您如何保存提到的列表?

如果将HTML存储在数据库中,则只需几步之遥即可:您可以使用strip_tags()删除HTML格式,并且strip_tags()较大更改的情况下,可以在代码上运行HTML Tidy来重新映射标签并类。

I see it as a better practice to store raw user input in the database, and format it on output, caching the result if it is needed. 我认为将原始用户输入存储在数据库中并在输出上设置其格式,并在需要时将结果缓存是一种更好的做法。 That way you can change the way you are parsing things easily without having to regex-replace anything inside the database. 这样,您可以更改轻松解析内容的方式,而不必正则表达式替换数据库中的任何内容。 You can also store the raw input in one column, and the formatted HTML in another one. 您也可以将原始输入存储在一列中,将格式化的HTML存储在另一列中。

I assume that you are formatting your raw text with the Markdown or the Textile syntax? 我假设您正在使用MarkdownTextile语法格式化原始文本?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM