php获取汉字首字母并排序出现大量NOTIC错误,大神
程序员文章站
2024-01-04 18:32:04
...
function getFirstChar($str){
if(empty($str)){
return '';
}
$fchar=ord($str{0});
if($fchar>=ord('A')&&$fchar return strtoupper($str{0});
}
$s1 = iconv('UTF-8', 'GB18030',$str);
$s2 = iconv('GB18030','UTF-8',$s1);
$s=$s2==$str?$s1:$str;
$asc=ord($s{0})*256+ord($s{1})-65536;
if($asc>=-20319&&$asc if($asc>=-20283&&$asc if($asc>=-19775&&$asc if($asc>=-19218&&$asc if($asc>=-18710&&$asc if($asc>=-18526&&$asc if($asc>=-18239&&$asc if($asc>=-17922&&$asc if($asc>=-17417&&$asc if($asc>=-16474&&$asc if($asc>=-16212&&$asc if($asc>=-15640&&$asc if($asc>=-15165&&$asc if($asc>=-14922&&$asc if($asc>=-14914&&$asc if($asc>=-14630&&$asc if($asc>=-14149&&$asc if($asc>=-14090&&$asc if($asc>=-13318&&$asc if($asc>=-12838&&$asc if($asc>=-12556&&$asc if($asc>=-11847&&$asc if($asc>=-11055&&$asc return null;
}
NOTIC: [8] iconv(): Detected an illegal character in input string D:\develop\upupw\htdocs\shixiapi\App\Common\Common\function.php 第 1157 行.
NOTIC: [8] iconv(): Detected an illegal character in input string D:\develop\upupw\htdocs\shixiapi\App\Common\Common\function.php 第 1157 行.
NOTIC: [8] iconv(): Detected an illegal character in input string D:\develop\upupw\htdocs\shixiapi\App\Common\Common\function.php 第 1157 行.
规矩点就
GB18030 标准虽然发布,但尚未在任何系统中实现
if(empty($str)){
return '';
}
$fchar=ord($str{0});
if($fchar>=ord('A')&&$fchar return strtoupper($str{0});
}
$s1 = iconv('UTF-8', 'GB18030',$str);
$s2 = iconv('GB18030','UTF-8',$s1);
$s=$s2==$str?$s1:$str;
$asc=ord($s{0})*256+ord($s{1})-65536;
if($asc>=-20319&&$asc if($asc>=-20283&&$asc if($asc>=-19775&&$asc if($asc>=-19218&&$asc if($asc>=-18710&&$asc if($asc>=-18526&&$asc if($asc>=-18239&&$asc if($asc>=-17922&&$asc if($asc>=-17417&&$asc if($asc>=-16474&&$asc if($asc>=-16212&&$asc if($asc>=-15640&&$asc if($asc>=-15165&&$asc if($asc>=-14922&&$asc if($asc>=-14914&&$asc if($asc>=-14630&&$asc if($asc>=-14149&&$asc if($asc>=-14090&&$asc if($asc>=-13318&&$asc if($asc>=-12838&&$asc if($asc>=-12556&&$asc if($asc>=-11847&&$asc if($asc>=-11055&&$asc return null;
}
NOTIC: [8] iconv(): Detected an illegal character in input string D:\develop\upupw\htdocs\shixiapi\App\Common\Common\function.php 第 1157 行.
NOTIC: [8] iconv(): Detected an illegal character in input string D:\develop\upupw\htdocs\shixiapi\App\Common\Common\function.php 第 1157 行.
NOTIC: [8] iconv(): Detected an illegal character in input string D:\develop\upupw\htdocs\shixiapi\App\Common\Common\function.php 第 1157 行.
回复讨论(解决方案)
简单点就
$s1 = @iconv('UTF-8', 'GB18030',$str);$s2 = @iconv('GB18030','UTF-8',$s1);
规矩点就
$s = mb_check_encoding($str, 'utf-8') ? iconv('utf-8', 'gbk', $str) : $str;
GB18030 标准虽然发布,但尚未在任何系统中实现