简体   繁体   English

显示来自数据库的富文本

[英]Showing rich text from database

I have stored rich text in my db, and now I would like to show it to the website viewers, but when I echo the content I got this:我已经在我的数据库中存储了富文本,现在我想向网站查看者展示它,但是当我回显内容时,我得到了这个:

<p>sometext</p><strong>text</strong>

I would like to remove the 'P' tags and any other tags from the text.我想从文本中删除“P”标签和任何其他标签。 I have used Ckeditor to store the rich text into DB.我使用 Ckeditor 将富文本存储到数据库中。 I could use Ckeditor to show the rich text to the website viewers, but Ckeditor is an editor and I would like only to show the rich text.我可以使用 Ckeditor 向网站查看者显示富文本,但 Ckeditor 是一个编辑器,我只想显示富文本。

Is there any in-built php command to convert the stored text into rich text and display it on my website?是否有任何内置的 php 命令将存储的文本转换为富文本并显示在我的网站上?

Well "rich text" is has its own format.好吧,“富文本”有自己的格式。 It's not xml like.它不是 xml 之类的。 So for example, a simple file where I will try to infer formatting of:因此,例如,我将尝试推断以下格式的简单文件:

Hello
This is bold
This italic

Looks like this in "rich text":在“富文本”中看起来像这样:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\f0\fs22 Hello\par
\b This is bold\b0\par
\i This italic\i0\par
\par
}

So it is not so simple to get this into HTML.所以把这个放到 HTML 中并不是那么简单。

I'ts straight forward on steps to get it into html (some text parsing involved, and a loop) but from your question it doesnt seem like you are (1) aware of it's format, and (2) haven't tried to write code to make it html?我对将其放入 html 的步骤很直接(涉及一些文本解析和一个循环),但从您的问题来看,您似乎(1)不知道它的格式,并且(2)没有尝试写使其成为 html 的代码?

I can add to this answer if you have actually tried on how the parsing steps might go.如果您实际尝试过解析步骤如何 go,我可以添加到这个答案中。 I can add now but want to get more information so as not to provide useless code, say if you are already using an API that does the deed.我现在可以添加,但想获取更多信息,以免提供无用的代码,比如您是否已经在使用 API 来执行此操作。

I use Draft.js with React.js but I hope this helps.我将 Draft.js 与 React.js 一起使用,但我希望这会有所帮助。 if you're still facing this issue: You can see the solution in this video如果您仍然面临此问题:您可以在此视频中看到解决方案

Basically you have to convertToRaw, then JSON.stringify it.基本上你必须转换ToRaw,然后JSON.stringify它。 Then this can be sent to your backend as a string.然后可以将其作为字符串发送到您的后端。 To display it, make a GET request for that particular data, then JSON.parse it and then convertFromRaw.要显示它,请对该特定数据发出 GET 请求,然后 JSON.parse 它,然后 convertFromRaw。 Pass this into another RichTextEditor as the editorState but set the readOnly={true}将此作为 editorState 传递给另一个 RichTextEditor,但设置 readOnly={true}

Find the methods for your particular editor which allows you to convert states and display it.为您的特定编辑器找到允许您转换状态并显示它的方法。

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

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