Go to the documentation of this file.00001 <?php
00002
00004 function match_aliases($str) {
00005 if (!preg_match_all('/Alias:\s*(\S+)/S', $str, $matches) ||
00006 $matches[1][0] == 'None') {
00007 return array();
00008 }
00009
00010 return $matches[1];
00011
00012 }
00013
00014
00016 function test_charset($charset) {
00017 return (bool) @iconv($charset, 'UTF-8', 'a');
00018 }
00019
00020
00021
00022 $file = file_get_contents('http://www.iana.org/assignments/character-sets');
00023
00024 preg_match_all('/Name:\s*(\S+).*[\r\n]+MIBenum:.*[\r\n]+Source:.*[\r\n]+((?:Alias:\s*\S+.*[\r\n]+)*)/', $file, $charsets);
00025
00026 array_shift($charsets);
00027 $charsets[1] = array_map('match_aliases', $charsets[1]);
00028 usort($charsets[0], 'strnatcasecmp');
00029
00030 $total = count($charsets[0]);
00031 $total_alias = count($charsets[1]);
00032 $ok = 0;
00033 $aliases = 0;
00034
00035 for ($i = 0; $i < $total; $i++) {
00036
00037 echo $charsets[0][$i] . ': ';
00038
00039 if (test_charset($charsets[0][$i])) {
00040 ++$ok;
00041 $valid[] = $charsets[0][$i];
00042 echo "true";
00043 $a = array();
00044
00045 foreach ($charsets[1][$i] as $alias) {
00046 if (test_charset($alias)) {
00047 ++$aliases;
00048 $a[] = $alias;
00049 }
00050 }
00051
00052 if($a = join($a, ', '))
00053 echo "; Valid aliases: $a";
00054
00055 echo "\n";
00056
00057 } else {
00058 echo "false\n";
00059 }
00060 }
00061
00062 echo "\n\n";
00063 print_r($valid);
00064 echo "\n\n";
00065
00066 echo number_format($ok * 100 / $total, 2, ',', '.') . "% of good charsets\n";
00067 echo number_format($aliases * 100 / $total_alias, 2, ',', '.') . "% of good aliases\n";
00068 echo "$total charsets\n";
00069
00070 ?>