2012-06-25 88 views
0

我有上面的這個函數來創建url posts從帖子標題,問題是ç characther沒有被轉換爲c。它實際上被功能覆蓋。S URL URL生成函數覆蓋Ç

實施例交標題:科拉桑德Pelúcia

蛞蝓生成:coraao-DE-pelucia

如何解決該功能可以生成如蛞蝓:科拉桑-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); 
} 

回答

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; 
} 
+0

seens工作正常。謝謝。 –