Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法从iconv获得所需的输出_Php - Fatal编程技术网

Php 无法从iconv获得所需的输出

Php 无法从iconv获得所需的输出,php,Php,当我调用上述函数时: function getCleanUrl($str, $replace=array(), $delimiter='-'){ setlocale(LC_COLLATE, 'en_GB'); if(!empty($replace)) { $str = str_replace((array)$replace, ' ', $str); } $clean = iconv('UTF-8', 'ASCII//TRANSLI

当我调用上述函数时:

function getCleanUrl($str, $replace=array(), $delimiter='-'){
    setlocale(LC_COLLATE, 'en_GB');
        if(!empty($replace)) {
        $str = str_replace((array)$replace, ' ', $str);
        }

    $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
    $clean = strtolower(trim($clean));
    $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);

    return $clean;

     }
输出:$cleanString==>>
ctnk-efter-nu-frr-n-vi-fser-dig-bort

它应该是
ctank-efter-nu-forr-n-vi-foser-dig-bort


仅供参考:

问题出在您的
setlocale()
行中。指定的区域设置可能不存在。试试这个:

   $str = "cTänk efter nu – förr'n vi föser dig bort";
   $replace = array("'","!",".");
   $cleanString = getCleanUrl($str,$replace);
如果没有,请尝试:

setlocale(LC_ALL, 'en_GB.UTF-8');
要列出系统上安装的区域设置,请通过命令行执行以下命令:

setlocale(LC_ALL, 'en_US.UTF-8');
$ locale -a