Slug URL生成函数覆盖Ç

时间:2012-06-25 02:59:24

标签: php special-characters slug

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

帖子标题示例:CoraçãodePelúcia

产生的slu :: coraao-de-pelucia

我如何修复此功能以生成像:coracao-de-pelucia

这样的slu ..
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);
}

1 个答案:

答案 0 :(得分:2)

您应该使用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;
}