终于可以给300分了循例发个小东西
class unicodeString
{
public function getNotLocaleChars($text, $unicode='UTF-8', $locale='GBK')
{
$transText1 = iconv($unicode, $locale.'//IGNORE', $text);
$transText2 = iconv($locale, $unicode, $transText1);
$transCharsArr2 = preg_split('##u', $transText2, -1, PREG_SPLIT_NO_EMPTY);
$transCharsArr1 = preg_split('##u', $text, -1, PREG_SPLIT_NO_EMPTY);
$charsArr = array_diff($transCharsArr1, $transCharsArr2);
return $charsArr;
}...
使用实例
$obj = new unicodeString();$str = 'hdshfhkdfs中文字典ㅏㅁ이ㅓㅣ잊';//获取编码为“参数2”的字串“参数1”中,不能转换为“参数3”编码的字符,输出为数组;
//参数2 省略时默认为“UTF-8”,参数3 省略时默认为“GBK”
$charArr = $obj->getNotLocaleChars($str,'utf-8', 'gbk');var_dump($charArr);//if (0===count($charArr)) $str 为完全本地“参数3”组成的字串80楼或帖子沉到第二版结贴
class unicodeString
{
public function getNotLocaleChars($text, $unicode='UTF-8', $locale='GBK')
{
$transText1 = iconv($unicode, $locale.'//IGNORE', $text);
$transText2 = iconv($locale, $unicode, $transText1);
$transCharsArr2 = preg_split('##u', $transText2, -1, PREG_SPLIT_NO_EMPTY);
$transCharsArr1 = preg_split('##u', $text, -1, PREG_SPLIT_NO_EMPTY);
$charsArr = array_diff($transCharsArr1, $transCharsArr2);
return $charsArr;
}...
使用实例
$obj = new unicodeString();$str = 'hdshfhkdfs中文字典ㅏㅁ이ㅓㅣ잊';//获取编码为“参数2”的字串“参数1”中,不能转换为“参数3”编码的字符,输出为数组;
//参数2 省略时默认为“UTF-8”,参数3 省略时默认为“GBK”
$charArr = $obj->getNotLocaleChars($str,'utf-8', 'gbk');var_dump($charArr);//if (0===count($charArr)) $str 为完全本地“参数3”组成的字串80楼或帖子沉到第二版结贴
$transText2 = iconv($locale, $unicode, $transText1);//再转回utf-8
$transCharsArr2 = preg_split('##u', $transText2, -1, PREG_SPLIT_NO_EMPTY);//切割
$transCharsArr1 = preg_split('##u', $text, -1, PREG_SPLIT_NO_EMPTY);//切割
$charsArr = array_diff($transCharsArr1, $transCharsArr2);//提取差异只有utf-8中的2字节部分不能被转换成gbk吧?