21,886
社区成员
发帖
与我相关
我的任务
分享
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”组成的字串