首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
回上頁
Anti SPAM: PHP compare similar string/text (with sorting)
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;
}


(3,501 views)
[更多討論] 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體
回上頁

"Anti SPAM: PHP compare similar string/text (with sorting)" 傳統頁面(電腦版)

首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
傳統桌面版 [ 登入/註冊 ]
© Vovo2000.com Mobile Version 小哈手機版 2024