Created
September 20, 2025 15:48
-
-
Save ziadoz/24c4f5e387dd430599c3b37da7b4e0d3 to your computer and use it in GitHub Desktop.
Download Unicode Database
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 | |
// Download Unicode database CSV: | |
$ch = curl_init(); | |
curl_setopt_array($ch, $options = [ | |
CURLOPT_URL => 'https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt', | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_TIMEOUT => 15, | |
CURLOPT_FAILONERROR => true, | |
]); | |
$data = curl_exec($ch); | |
if (! $data) { | |
echo 'Unable to download Unicode database: ' . curl_error($ch); | |
exit(1); | |
} | |
curl_close($ch); | |
file_put_contents(__DIR__ . '/UnicodeData.txt', $data); | |
// Format Unicode database as JSON: | |
$json = []; | |
$csv = fopen(__DIR__ . '/UnicodeData.txt', 'rb'); | |
while (($row = fgetcsv($csv, null, ';', '"', '')) !== false) { | |
$json[$row[0]] = $row[1]; | |
} | |
fclose($csv); | |
$object = json_encode($json, JSON_PRETTY_PRINT); | |
echo <<<JS | |
export const database = $object; | |
JS; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment