显示来自数据库的丰富文本
我已在数据库中存储了富文本,现在我想将其显示给网站查看者,但是当我回显内容时,我得到了以下信息:
<p>sometext</p><strong>text</strong>
我想从文本中删除“P”标签和任何其他标签。 我使用 Ckeditor 将富文本存储到数据库中。 我可以使用 Ckeditor 向网站查看者显示富文本,但 Ckeditor 是一个编辑器,我只想显示富文本。
是否有任何内置的 php 命令可以将存储的文本转换为富文本并将其显示在我的网站上?
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.
I have used Ckeditor to store the rich text into DB.
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.
Is there any in-built php command to convert the stored text into rich text and display it on my website?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么“富文本”有自己的格式。它不像 xml。例如,我将尝试推断一个简单文件的格式:
在“富文本”中看起来像这样:
因此将其转换为 HTML 并不那么简单。
我没有直接将其转换为 html 的步骤(涉及一些文本解析和循环),但从你的问题来看,你似乎并没有(1)意识到它的格式,并且(2)没有尝试编写代码使其成为html?
如果您实际上尝试过解析步骤可能会如何进行,我可以添加到这个答案。我现在可以添加,但想要获取更多信息,以免提供无用的代码,比如说您是否已经在使用执行此操作的 API。
Well "rich text" is has its own format. It's not xml like. So for example, a simple file where I will try to infer formatting of:
Looks like this in "rich text":
So it is not so simple to get this into 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?
I can add to this answer if you have actually tried on how the parsing steps might 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.
我将draft.js与react.js一起使用,但我希望这会有所帮助。如果您仍在面对这个问题:您可以在此
。您必须转换,然后json.stringing。然后,可以将其作为字符串发送到您的后端。要显示它,请对该特定数据进行获取请求,然后json.parse,然后convertfromraw。将其传递到另一个RichTexteditor作为编辑态,但设置ReadOnly = {true}
找到特定编辑器的方法,该方法允许您转换状态并显示它。
I use Draft.js with React.js but I hope this helps. if you're still facing this issue: You can see the solution in this video
Basically you have to convertToRaw, then JSON.stringify it. 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. Pass this into another RichTextEditor as the editorState but set the readOnly={true}
Find the methods for your particular editor which allows you to convert states and display it.