Created
May 12, 2014 07:14
-
-
Save octopitus/e1678310b611567d53a1 to your computer and use it in GitHub Desktop.
SEO friendly url converter for Vietnamese
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Take from https://gist.github.com/alixaxel/5562152 with some edits | |
*/ | |
function slugify($string, $slug = '-', $extra = null) { | |
if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false) { | |
$string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|caron|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8'); | |
} | |
if (preg_match('~[^[:ascii:]]~', $string) > 0) { | |
$latin = array( | |
'a' => '~[àáảãạăằắẳẵặâầấẩẫậÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬą]~iu', | |
'ae' => '~[ǽǣ]~iu', | |
'b' => '~[ɓ]~iu', | |
'c' => '~[ćċĉč]~iu', | |
'd' => '~[ďḍđɗð]~iu', | |
'e' => '~[èéẻẽẹêềếểễệÈÉẺẼẸÊỀẾỂỄỆęǝəɛ]~iu', | |
'g' => '~[ġĝǧğģɣ]~iu', | |
'h' => '~[ĥḥħ]~iu', | |
'i' => '~[ìíỉĩịÌÍỈĨỊıǐĭīįİ]~iu', | |
'ij' => '~[ij]~iu', | |
'j' => '~[ĵ]~iu', | |
'k' => '~[ķƙĸ]~iu', | |
'l' => '~[ĺļłľŀ]~iu', | |
'n' => '~[ʼnń̈ňņŋ]~iu', | |
'o' => '~[òóỏõọôồốổỗộơờớởỡợÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢǒŏōőǫǿ]~iu', | |
'r' => '~[ŕřŗ]~iu', | |
's' => '~[ſśŝşșṣ]~iu', | |
't' => '~[ťţṭŧ]~iu', | |
'u' => '~[ùúủũụưừứửữựÙÚỦŨỤƯỪỨỬỮỰǔŭūűůų]~iu', | |
'w' => '~[ẃẁŵẅƿ]~iu', | |
'y' => '~[ỳýỷỹỵYỲÝỶỸỴŷȳƴ]~iu', | |
'z' => '~[źżžẓ]~iu', | |
); | |
$string = preg_replace($latin, array_keys($latin), $string); | |
} | |
return strtolower(trim(preg_replace('~[^0-9a-z' . preg_quote($extra, '~') . ']++~i', $slug, $string), $slug)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment