Last active
October 28, 2022 08:33
-
-
Save PVince81/80c5416b8d927e7796420aac7edbd02e to your computer and use it in GitHub Desktop.
Test Unicode normalization of given file name
This file contains hidden or 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 | |
// ref: https://www.win.tue.nl/~aeb/linux/uc/nfc_vs_nfd.html | |
$s = $argv[1]; | |
if (\Normalizer::isNormalized($s, \Normalizer::FORM_D)) { | |
print("Original string is using NFD normalization\n"); | |
$nfc = \Normalizer::normalize($s, \Normalizer::FORM_C); | |
print("NFC: $nfc\n"); | |
print("NFD: $s\n"); | |
} elseif (\Normalizer::isNormalized($s, \Normalizer::FORM_C)) { | |
print("Original string is using NFC normalization\n"); | |
$nfd = \Normalizer::normalize($s, \Normalizer::FORM_D); | |
print("NFC: $s\n"); | |
print("NFD: $nfd\n"); | |
} else { | |
print("Unknown normalization\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment