Home > Backend Development > PHP Problem > How to convert php ascii to Chinese

How to convert php ascii to Chinese

藏色散人
Release: 2023-03-03 16:56:01
Original
4508 people have browsed it

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;);
    }
Copy after login

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!

Related labels:
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