每天我都会通过联系人表单收到大量的垃圾邮件。这些垃圾邮件的内容与下面的示例非常相似:
Ïîñëåäíèè íîâîñòè àðìåíèè ÷èòàéòå íà ñàéòå somedomainname.com对于这种特定类型的垃圾邮件,我想添加3个连续特殊字符的PHP检测,因为它永远不会出现在合法的电子邮件中(至少在过去10年中没有)。实现这一目标的聪明方法是什么?
编辑:我不确定我应该如何对这些字符进行分类。它们都有某种口音,如示例中所示。
发布于 2018-07-31 16:57:08
基于另一个问题:how to check for special characters php
您可以在邮件内容上使用正则表达式:
if (preg_match('/([Ïîñëåäíèè]){3}/', $contentOfMail))
{
// $contentOfMail contains at least one set of 3 specials characters back to back
}我允许您在regex中填充需要匹配的所有字符
发布于 2018-07-31 16:59:35
要检查是否存在一个或多个字母,可以使用本机function of PHP strpos,如下所示。另外,您也可以使用正则表达式,但对于基本验证和性能问题,建议使用原生PHP函数。
$mystring = $_POST['message'];
$findme = 'Ïîñëåäíèè';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}https://stackoverflow.com/questions/51609172
复制相似问题