3

我已经用谷歌搜索了它,其中大多数是关于阻止 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;

4

1 回答 1

1

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

如前所述,简单的方法是使用strip_tagsonhtmlspecialchars_decode函数。但是,它将删除一些可能重要的信息,例如 HR 元素。您更愿意使用的是html2text,它是一个非常容易使用的类,具有一些使转换更加准确的附加功能。

希望能帮助到你!

于 2013-01-31T10:30:47.630 回答