Apacheのmime.typesから、拡張子をキーとしてContent-Typeを値に持つPHP配列を作成させてみた。
YakiBikiで使うことになりそうなので、気分転換に。mime.types自体は
(content-type)(タブ1個以上)(ext)((空白)(ext)1個以上)
みたいな感じになってるので、tabを空白に変換してexplodeした後、一番目を値にして、2番目以降が拡張子になるので、それぞれをキーに指定して1番目を入れていけばよい。
というわけで、以下が convert_apache_mimetypes2phparray.php になります。適当でっちあげ。
$ php convert_apache_mimetypes2phparray.php mime.types > hoge.php
して、後でhoge.phpに適当に目鼻立ち整えてあげれば終了。
<?php if ($_SERVER['argc'] < 2) { echo "usage: php " . basename(__FILE__) . " <Apache's mime.types file>" . PHP_EOL; exit(0); } $fn_mt = $_SERVER['argv'][1]; $lines = file($fn_mt); if ($lines === false) { exit(0); } $lines = array_map('trim', $lines); $mapping = array(); foreach ($lines as $l) { if ($l == '') { continue; } if ($l{0} == "#") { continue; } $s = str_replace("\t", ' ', $l); $_els = array_map('trim', explode(' ', $s)); $__els = array(); foreach ($_els as $_e) { if ($_e != "") { $__els[] = $_e; } } if (count($__els) < 2) { continue; } $mt = array_shift($__els); while($ext = array_shift($__els)) { if(isset($mapping[$ext])) { echo "!!!! [$ext] duplicated!!!!".PHP_EOL; } $mapping[$ext] = $mt; } } ksort($mapping); var_export($mapping);