Posted by & filed under OSS Localization. Edit: 23 November 2015

... usually after having tried tons of snippets and I got this php code for non-WP (or WP) websites.

To remove all accents from title but also leave clean-and-understandable slug remaining, applied for all types of languages with strange accents:

Pizza-pasta-grillPhoto: Quinn Dombrowski

(!!! Save UTF-8 without BOM!!!)

function generateSafeUrls($url) {
$url = preg_replace("/(ä|à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $url);
$url = str_replace("ç","c",$url);
$url = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $url);
$url = preg_replace("/(ì|í|î|ị|ỉ|ĩ)/", 'i', $url);
$url = preg_replace("/(ö|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $url);
$url = preg_replace("/(ü|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $url);
$url = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $url);
$url = preg_replace("/(đ)/", 'd', $url);

$url = preg_replace("/(Ä|À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $url);
$url = str_replace("Ç","C",$url);
$url = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $url);
$url = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $url);
$url = preg_replace("/(Ö|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $url);
$url = preg_replace("/(Ü|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $url);
$url = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $url);
$url = preg_replace("/(Đ)/", 'D', $url);
//Special string
$url = preg_replace("/(|!||#|$|%|')/", '', $url);
$url = preg_replace("/(̀|́|̉|$|>)/", '', $url);
$url = preg_replace ("'< [\/\!]*?[^<>]*?>'si", "", $url);
/*
$url = str_replace(" / ","-",$url);
$url = str_replace("/","-",$url);
$url = str_replace(" - ","-",$url);
$url = str_replace("_","-",$url);
$url = str_replace(" ","-",$url);
$url = str_replace( "ß", "ss", $url);
$url = str_replace( "&", "", $url);
$url = str_replace( "%", "", $url);
$url = ereg_replace("[^A-Za-z0-9-]", "", $url);
*/
$url = str_replace("----","-",$url);
$url = str_replace("---","-",$url);
$url = str_replace("--","-",$url);

$url = str_replace(" ","-",$url);
$url = str_replace("*","-",$url);

return $url;
}

./.

Comments

comments

Comments are closed.