Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2010-01-05 15:26:44

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

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

Board footer

Powered by FluxBB