/**
* 将字符串拆成数组
* @param string $string:字符串
* @return 返回拆成的数组
*/
function mbStringToArray ($string) {
$string = $this->getChinaEnglishNumString($string);
$array = array();
$strlen = mb_strlen($string);
while ($strlen) {
$array[] = mb_substr($string,0,1,"utf8");
$string = mb_substr($string,1,$strlen,"utf8");
$strlen = mb_strlen($string);
}
return $array;
}
/**
* 获取字符串中文、数字、字母、下划线
* @param string $str:字符串
* @param string $charset:编码
* @return boolean|string
*/
function getChinaEnglishNumString($str,$charset=‘utf8‘){
if($charset==‘gb2312‘){
if(!preg_match_all("/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_\-]+/",$str,$match)){
return false;
}
return implode(‘‘,$match[0]);
}
if($charset==‘utf8‘){
if(!preg_match_all("/[\x{4e00}-\x{9fa5}A-Za-z0-9_\-]+/u",$str,$match)){
return false;
}
return implode(‘‘,$match[0]);
}
return false;
}
原文地址:http://ouyangjun.blog.51cto.com/10284323/1740525