Slug URL generation function overriding the Ç

北城以北 提交于 2019-12-12 03:45:00

问题


I have this function above to create url slugs from posts title, the problem is that the ç characther is not being converted to c. It is actually being override by the function.

Example post title: Coração de Pelúcia

The slug generated: coraao-de-pelucia

How can i fix this function to generate the slug like: 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);
}

回答1:


You should use the iconv module and a function such as this one to do the conversion:

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


来源:https://stackoverflow.com/questions/11183010/slug-url-generation-function-overriding-the-%c3%87

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!