Home > Backend Development > PHP Tutorial > php获取汉字首字母并排序出现大量NOTIC错误,大神

php获取汉字首字母并排序出现大量NOTIC错误,大神

WBOY
Release: 2016-06-23 13:21:45
Original
1399 people have browsed it

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 行.


回复讨论(解决方案)

简单点就

$s1 = @iconv('UTF-8', 'GB18030',$str);$s2 = @iconv('GB18030','UTF-8',$s1);  
Copy after login

规矩点就
$s = mb_check_encoding($str, 'utf-8') ? iconv('utf-8', 'gbk', $str) : $str;
Copy after login


GB18030 标准虽然发布,但尚未在任何系统中实现

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template