gpt4 book ai didi

php - 在 PHP 中从数据库中删除 TinyMCE 格式

转载 作者:搜寻专家 更新时间:2023-10-31 21:39:52 26 4
gpt4 key购买 nike

我用谷歌搜索了一下,其中大部分都是关于阻止 TinyMCE 粘贴 JavaScript 角度的 Word 样式。

我的问题是数据已经在数据库中 (MySQL) 以及用户通过 TinyMCE 粘贴 MS Words 文本所做的所有格式设置。

有没有办法通过使用 PHP 去除所有格式并只保留文本?

一些示例文本:

&lt;!--  /* Font Definitions */  @font-face     {font-family:"Cambria Math";    panose-1:2 4 5 3 5 4 6 3 2 4;   mso-font-charset:1;     mso-generic-font-family:roman;  mso-font-format:other;  mso-font-pitch:variable;    mso-font-signature:0 0 0 0 0 0;} @font-face     {font-family:Calibri;   panose-1:2 15 5 2 2 2 4 3 2 4;  mso-font-charset:0;     mso-generic-font-family:swiss;  mso-font-pitch:variable;    mso-font-signature:-1610611985 1073750139 0 0 159 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal    {mso-style-unhide:no;   mso-style-qformat:yes;  mso-style-parent:"";    margin-top:0in;     margin-right:0in;   margin-bottom:10.0pt;   margin-left:0in;    line-height:115%;   mso-pagination:widow-orphan;    font-size:11.0pt;   font-family:"Calibri","sans-serif";     mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;   mso-fareast-font-family:Calibri;    mso-fareast-theme-font:minor-latin;     mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;   mso-bidi-font-family:"Times New Roman";     mso-bidi-theme-font:minor-bidi;     mso-fareast-language:EN-US;} .MsoChpDefault     {mso-style-type:export-only;    mso-default-props:yes;  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;   mso-fareast-font-family:Calibri;    mso-fareast-theme-font:minor-latin;     mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;   mso-bidi-font-family:"Times New Roman";     mso-bidi-theme-font:minor-bidi;     mso-fareast-language:EN-US;} .MsoPapDefault     {mso-style-type:export-only;    margin-bottom:10.0pt;   line-height:115%;} @page Section1   {size:8.5in 11.0in;     margin:1.0in 1.0in 1.0in 1.0in;     mso-header-margin:.5in;     mso-footer-margin:.5in;     mso-paper-source:0;} div.Section1   {page:Section1;} --&gt;   Blah blah blah blah blah &nbsp;    </p>

注意:HTML标签作为html实体存储在数据库中(例如字符<存储为&lt;)

最佳答案

您要做的是将 HTML 转换为纯文本。因为这基本上就是您将从 TinyMCE 中获得的内容以及您想要插入数据库的内容。

如前所述,实现这一点的简单方法是在 htmlspecialchars_decode 函数上使用 strip_tags。但是,它会删除一些可能重要的信息,例如 HR 元素。您更有可能使用的是 html2text这是一个非常容易使用的类,带有一些使转换更加准确的附加功能。

希望对您有所帮助!

关于php - 在 PHP 中从数据库中删除 TinyMCE 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12482580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com