Solve the problem of php receiving the result from shell
- 2020-12-16 05:53:59
- OfStack
If php is required to execute 1 of the shell commands and view the results displayed, if shell outputs Chinese, php may return something like "? \ 230? \ 180? \ 187? \ 229? \ 138? \168 "string. Then you need this function translation:
// This function accepts all paths, so it determines the file extension
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;
// Determines if there is a file extension
$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);
}