• Source
    1. <?php
    2. $emails = array(
    3. "Dkstu@studio.com.tw",
    4. "Dkstu@studio.com.tw​"
    5. );
    6.  
    7. echo " Test1 => " . (($emails[0] === $emails[1])? "Same" : "Diff") . "\n" ;
    8.  
    9. echo "-- Check Length --\n"
    10. . "LENGTH: ". strlen($emails[0]) . " => " . implode(":", utf8_str_split($emails[0])) . "\n"
    11. . "LENGTH: ". strlen($emails[1]) . " => " . implode(":", utf8_str_split($emails[1])) . "\n" ;
    12.  
    13. echo "- - - - - - - - - - - - - - - - - - -\n";
    14. ($emails[0]=clear_utf8 ($emails[0])) && ($emails[1]=clear_utf8 ($emails[1])); // 去除中文(UTF-8)空格
    15.  
    16. echo " Test2 => " . (($emails[0] === $emails[1])? "Same" : "Diff") . "\n" ;
    17.  
    18. echo "-- Check Length --\n"
    19. . "LENGTH: ". strlen($emails[0]) . " => " . implode(":", utf8_str_split($emails[0])) . "\n"
    20. . "LENGTH: ". strlen($emails[1]) . " => " . implode(":", utf8_str_split($emails[1])) . "\n" ;
    21.  
    22.  
    23.  
    24.  
    25. function utf8_str_split($str, $split_len = 1) {
    26. if (!preg_match('/^[0-9]+$/', $split_len) || $split_len < 1)
    27. return FALSE;
    28. $len = mb_strlen($str, 'UTF-8');
    29. if ($len <= $split_len)
    30. return array($str);
    31. preg_match_all('/.{'.$split_len.'}|[^\x00]{1,'.$split_len.'}$/us', $str, $ar);
    32. return $ar[0];
    33. }
    34.  
    35. function clear_utf8 ($str) {
    36. return preg_replace('/([\x80-\xff]*)/i', '', $str);
    37. }