Type(Type) 2014/11/2 17:08
Anti SPAM: PHP compare similar string/text (with sorting)
PHP::similar_text will be defeated by shuffling the text sequence,
this function try to sort before compare similar string.
Note: This only considers "\n"(LF) as token,
you could add more delimiter/separator. (e.g. "space", "period")
代碼:
function compare_similar_str($var_1, $var_2)
{
$a1 = array();
$a2 = array();
$percent = 0;
// You could add more delimiter/separators to fit your need
$a1 = explode("\n", str_replace(' ', '', $var_1));
$a2 = explode("\n", str_replace(' ', '', $var_2));
sort($a1);
sort($a2);
$var_1 = implode('', $a1);
$var_2 = implode('', $a2);
similar_text($var_1, $var_2, $percent);
return intval($percent);
}
Type(Type) 2014/11/7 14:26
PHP: remove_symbols
This co-works with compare_similar_str() to achieve preliminary anti-spam
代碼:
/*
* Replace symbols --> compare to achieve preliminary spam-proof
*/
function remove_symbols($this_str)
{
$symbols = array('‘','’',':',',',';','。',',','"',';','、','~','@','#','$','%','︿','&','*',
'/','!','@','#','$','%',':','^','&','*','(',')','-','_','+','=','{','[','}',']','?',
'<','>','~', "\n", '\\',
'╳','○','☆','★','□','■','●','【','】','「','」','『','』','〈','〉',
'【','】','「','」','『','』','〈','〉','《','》','〔','〕','{','}','↑','↓','←','→','↖','↗','↙','↘','╳','○','☆',
'☻','☺','♠','♣','♥','♦','♪','♀','♂','㊣', "'", ' ',
);
$test = str_replace($symbols, '', $this_str);
return $test;
}
(6,242 views)
© Vovo2000.com Mobile Version 小哈手機版 2024