Skip to content

Instantly share code, notes, and snippets.

@satooshi
Last active January 18, 2016 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satooshi/48fe74ebf76623ec2d0c to your computer and use it in GitHub Desktop.
Save satooshi/48fe74ebf76623ec2d0c to your computer and use it in GitHub Desktop.
Get NFC and NFD string of Vietnamese characters.
<?php
# http://www.unicode.org/charts/PDF/U1E00.pdf
$targets = [
'aắằặấầẩậẳẵạàáâãảăẫ',
'eẽẹếềểễệèéêẻ',
'oốồổỗộờởơớỡòóôõỏọợ',
'iịìíĩỉ',
'uứừửưữựụùúũủ',
'yỳỷỹỵý'
];
# http://php.net/manual/en/class.normalizer.php
foreach ($targets as $target) {
$str1 = Normalizer::normalize($target, Normalizer::FORM_D);
var_dump($str1);
$str2 = Normalizer::normalize($target, Normalizer::FORM_C);
var_dump($str2);
}
/*
string(72) "aắằặấầẩậẳẵạàáâãảăẫ"
string(47) "aắằặấầẩậẳẵạàáâãảăẫ"
string(44) "eẽẹếềểễệèéêẻ"
string(31) "eẽẹếềểễệèéêẻ"
string(72) "oốồổỗộờởơớỡòóôõỏọợ"
string(47) "oốồổỗộờởơớỡòóôõỏọợ"
string(16) "iịìíĩỉ"
string(13) "iịìíĩỉ"
string(44) "uứừửưữựụùúũủ"
string(30) "uứừửưữựụùúũủ"
string(16) "yỳỷỹỵý"
string(15) "yỳỷỹỵý"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment