$entry) { $idx = strpos($file, $entry); if ($idx === false) { $idx = strlen($file); $file .= $entry; } $offsets[$TZ] = $idx; } // now output the result unset($data, $idx); uksort($offsets, 'strcasecmp'); echo "/* This is a generated file, do not modify */\n\n"; echo "static const timelib_tzdb_index_entry timezonedb_idx_builtin[".sizeof($offsets)."] = {\n"; foreach ($offsets as $TZ => $offset) { echo "\t{ ".sprintf('%-36s, 0x%06X', '"'.$TZ.'"', $offset). " },\n"; } echo "};\n"; echo "\nstatic const unsigned char timelib_timezone_db_data_builtin[".strlen($file)."] = {\n"; $size = strlen($file); for ($i = 0; $i < $size; ++$i) { printf("0x%02X, ", ord($file[$i])); if ($i % 16 == 15) { echo "\n"; } } echo "};\n\n"; function sort_by_size($a, $b) { $sa = strlen($a); $sb = strlen($b); if ($sa > $sb) return -1; if ($sa < $sb) return 1; return 0; }