我正在尝试从电子邮件中删除特殊字符和多个空行,目前我正在使用条带替换和标记的组合但是有一些问题。
PHP:
$message=strip_tags($message, "<br><p><u><span><hr><section>");
$message=preg_replace("/(<br\ ?\/?>)+/", "<br/>", $message);
$message=preg_replace( "/\s+/", " ", $message );
$message = str_replace('<p class=MsoNormal><o:p> </o:p></p>', '', $message);
输出是:
________________________________________
Hi,
My comp= uter and php code is acting up.
=
This is just= a test email with whitespaces J
=
= =
我正在发送一条带有Outlook的消息,看起来它正在用
替换每个空行<p class=MsoNormal><o:p> </o:p></p>
如何在没有任何内容的情况下替换它,删除多个空行并删除所有=字符。有什么建议?
原始类型的消息如下所示:
Hi,
My computer and php code is acting up.
This is just a test email with whitespaces :)
这就是在发送电子邮件之前Outlook代码的样子。
<p class=MsoNormal style='mso-layout-grid-align:none;text-autospace:none'><span
style='mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri;mso-bidi-font-family:
Calibri;color:black'><o:p> </o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Hi,<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>My computer and php code is acting up.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>This is just a test email with whitespaces <span
style='font-family:Wingdings'>J</span><o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
感谢。
答案 0 :(得分:1)
不是完美的解决方案,但似乎有效:
<?php
$s = 'Hi,
My comp= uter and php code is acting up.
=
This is just= a test email with whitespaces J
=
= = ';
$s = preg_replace('/=\s/', '', $s);
$s = preg_replace('/\n\n/', "", $s);
echo $s;
打印
Hi,My computer and php code is acting up.
This is justa test email with whitespaces J
答案 1 :(得分:-1)
使用HTML Purifier - 它是一个用PHP编写的符合标准的HTML过滤器库。