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

How to convert Chinese to ascii in php

藏色散人
藏色散人Original
2020-07-29 09:36:582968browse

How to convert Chinese to ascii: First create a PHP sample file; then define a "strtoascii" method; then use the "mb_convert_encoding" function to convert the encoding; finally execute the file and output the conversion result.

How to convert Chinese to ascii in php

Recommended: "PHP Tutorial"

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

public function strtoascii($str){
        $str=mb_convert_encoding($str,'GB2312');
        $change_after='';
        for($i=0;$i

The above is the detailed content of How to convert Chinese to ascii in php. 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