怎样将php里的汉字字符串分割成单个字符
1个回答
展开全部
如果你的字串是固定的,就先用substr() 固定截图来赋值把,(汉子截取2个字节)
$str = "怎么chai数组123";
function str_arr($str){
$str1 = substr($str,0,1);
echo $str1;
$e = preg_match("/^[\x7f-\xff]+$/",$str1);
echo $e;
if($e){$zhi = "y"; }else{$zhi = 'n';}
echo $zhi;
$new = array();
if($e){
$new[] = $str1;
$str_r = substr($str,2);
}else{
$str2 = substr($str,0,2);
$new[] = $str2;
$str_r = substr($str,2);
}
return $new;
}
$ss = str_arr($str);
var_dump($ss);
$str = "怎么chai数组123";
function str_arr($str){
$str1 = substr($str,0,1);
echo $str1;
$e = preg_match("/^[\x7f-\xff]+$/",$str1);
echo $e;
if($e){$zhi = "y"; }else{$zhi = 'n';}
echo $zhi;
$new = array();
if($e){
$new[] = $str1;
$str_r = substr($str,2);
}else{
$str2 = substr($str,0,2);
$new[] = $str2;
$str_r = substr($str,2);
}
return $new;
}
$ss = str_arr($str);
var_dump($ss);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询