Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Can't use permalink with non-English title ?
these are my two functions to convert vietnamese characters to rough ASCII equivalent. hope this help
function deLocalize($inStr)
{
$outStr = $inStr;
$outStr = preg_replace('@[éÉèÈẻẺẽẼẹẸêÊếẾềỀểỂễỄệỆ]@u', 'e', $outStr);
$outStr = preg_replace('@[úÚùÙủỦũŨụỤưƯứỨừỪửỬữỮựỰ]@u', 'u', $outStr);
$outStr = preg_replace('@[íÍìÌỉỈĩĨịỊ]@u', 'i', $outStr);
$outStr = preg_replace('@[óÓòÒỏỎõÕọỌôÔơƠốỐồỒổỔỗỖộỘớỚờỜởỞỡỠợỢ]@u', 'o', $outStr);
$outStr = preg_replace('@[áÁàÀảẢãÃạẠâÂăĂấẤầẦẩẨẫẪậẬắẮằẰẳẲẵẴặẶ]@u', 'a', $outStr);
$outStr = preg_replace('@[đĐ]@u', 'd', $outStr);
return $outStr;
}
function seftitle($yourtitle)
{
$str = deLocalize($yourtitle);
$str = strtolower($str);
$str = preg_replace('@[^a-z 0-9]+@u', '', $str);
$str = preg_replace('@\s+@u', "-", $str);
return $str;
}
echo seftitle("tiêu đề bài viết phù hợp") will produce a proper title => tieu-de-bai-viet-phu-hop
Last edited by HAC (2010-01-05 15:28:38)
Offline