php 如何比较两个中文字符串是否相等

如题所述

function arr_split_zh($tempaddtext){
$cind = 0;
$arr_cont=array();

for($i=0;$i<strlen($tempaddtext);$i++)
{
if(strlen(substr($tempaddtext,$cind,1)) > 0){
if(ord(substr($tempaddtext,$cind,1)) < 0xA1 ){ //如果为英文则取1个字节
array_push($arr_cont,substr($tempaddtext,$cind,1));
$cind++;
}else{
array_push($arr_cont,substr($tempaddtext,$cind,2));
$cind+=2;
}
}
}
return $arr_cont;
}
$str1="中文字符串1";
$str2="中文字符串2";

$Arr_Str1 = arr_split_zh($str1);
$Arr_Str2 = arr_split_zh($str2);

function Str_Is_Equal($mystr1,$mystr2){
$result = 0;
for($i=0;$mystr1[$i];$i++){
if($mystr1[$i] !=$mystr2[$i]){
$result = 0;
break;
}
$result = 1;
}
return $result;
}
看看行不?我这边Apache环境有点问题,所以没有测试
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-17
是用运算符还是函数
第2个回答  2011-09-30
不可以直接用==比较么.
if ($a==$b)
相似回答