【问题标题】:Slug URL generation function overriding the ÇSlug URL 生成函数覆盖Ç
【发布时间】:2012-06-26 08:02:39
【问题描述】:

我上面有这个函数来从帖子标题创建 url slugs,问题是ç 字符没有被转换为c。它实际上被函数覆盖了。

示例帖子标题:Coração de Pelúcia

生成的蛞蝓:coraao-de-pelucia

我怎样才能修复这个函数来生成这样的蛞蝓:coracao-de-pelucia

function generate_seo_link($input,$replace = '-',$remove_words = true,$words_array = array())
{
    //make it lowercase, remove punctuation, remove multiple/leading/ending spaces
    $return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($input))));

    //remove words, if not helpful to seo
    //i like my defaults list in remove_words(), so I wont pass that array
    if($remove_words) { $return = remove_words($return,$replace,$words_array); }

    //convert the spaces to whatever the user wants
    //usually a dash or underscore..
    //...then return the value.
    return str_replace(' ',$replace,$return);
}

【问题讨论】:

    标签: php special-characters slug


    【解决方案1】:

    你应该使用 iconv 模块和一个这样的函数来进行转换:

    function url_safe($string){
        $url = $string;
        setlocale(LC_ALL, 'pt_BR'); // change to the one of your language
        $url = iconv("UTF-8", "ASCII//TRANSLIT", $url);  
        $url = preg_replace('~[^\\pL0-9_]+~u', '-', $url);
        $url = trim($url, "-");
        $url = strtolower($url);
        return $url;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-30
      • 2014-06-17
      • 2013-09-11
      • 2014-12-09
      • 2011-03-06
      • 2013-09-19
      • 1970-01-01
      相关资源
      最近更新 更多