Home  >  Article  >  Backend Development  >  How to convert php ascii to Chinese

How to convert php ascii to Chinese

藏色散人
藏色散人Original
2020-08-01 10:39:394493browse

php How to convert ascii to Chinese: First create a PHP sample file; then define an asciitostr method; then convert ascii to Chinese through functions such as "mb_convert_encoding".

How to convert php ascii to Chinese

Recommended: "PHP Video Tutorial"

Convert ascii to string (Chinese is also practical) (note : I default that our current php file environment is UTF-8. If it is GBK, the mb_convert_encoding operation is not needed)

public function asciitostr($sacii){
        $asc_arr= str_split(strtolower($sacii),2);
        $str='';
        for($i=0;$i<count($asc_arr);$i++){
            $str.=chr(hexdec($asc_arr[$i][1].$asc_arr[$i][0]));
        }
        return mb_convert_encoding($str,&#39;UTF-8&#39;,&#39;GB2312&#39;);
    }

The above is the detailed content of How to convert php ascii to Chinese. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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