function build_function() { if ($charsets = build_character_set_list()) { $return = <<<EOF function charset(\$charset) { \t/* Character sets are case-insensitive, and also need some further \tnormalization in the real world (though we'll return them in the form given \tin their registration). */ \tswitch (strtolower(preg_replace('/[\\x09-\\x0D\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E]/', '', \$charset))) \t{ EOF; foreach ($charsets as $preferred => $aliases) { foreach ($aliases as $alias) { $return .= "\t\tcase " . var_export($alias, true) . ":\n"; } $return .= "\t\t\treturn " . var_export($preferred, true) . ";\n\n"; } $return .= <<<EOF \t\tdefault: \t\t\treturn \$charset; \t} } EOF; return $return; } else { return false; } }
function build_function() { if ($charsets = build_character_set_list()) { $return = <<<EOF function charset(\$charset) { \t// Normalization from UTS #22 \tswitch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\\1', \$charset))) \t{ EOF; foreach ($charsets as $preferred => $aliases) { foreach ($aliases as $alias) { $return .= "\t\tcase " . var_export($alias, true) . ":\n"; } $return .= "\t\t\treturn " . var_export($preferred, true) . ";\n\n"; } $return .= <<<EOF \t\tdefault: \t\t\treturn \$charset; \t} } EOF; return $return; } else { return false; } }