Home  >  Article  >  Backend Development  >  After php receives the results returned by the shell, the solution to Chinese garbled characters_PHP tutorial

After php receives the results returned by the shell, the solution to Chinese garbled characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:37:151014browse

如果需要php执行一些shell命令,查看显示结果的话,如果shell输出的有中文,则php得到的中文返回结果可能类似是 “?\230?\180?\187?\229?\138?\168” 的字符串。那么需要这个函数转译:

//这个函数接收的都是路径,所以判断了文件扩展名 
function shell2txt($a){
    $ary = explode('/', $a);
    foreach($ary as $k => $v){
            if(strpos($v, '?\\') !== false){
                    $_ary = explode('?\\', $v);

                    foreach($_ary as $_k=>$_v){
                            if($_v == '') continue;
                            //判断是否有文件扩展名
                            $end = '';
                            if(strpos($_v, '.') !== false){
                                    $end = substr($_v, strpos($_v, '.'));
                            }
                            $_ary[$_k] = dechex($_v).$end;
                    }

                    $ary[$k] = implode('%', $_ary);
            }
    }

    $a = implode('/', $ary);
    return  urldecode($a);
}


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735905.htmlTechArticle如果需要php执行一些shell命令,查看显示结果的话,如果shell输出的有中文,则php得到的中文返回结果可能类是 “?\230?\180?\187?\229?\138?\168”...
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