public static function generate($file) { extract(GeoName::$files[$file]); $srcFile = PhpArray::fetch($src, $srcFile); echo sprintf("-> Parsing %s\n", basename($srcFile)); $items = array(); $fp = fopen($srcFile, "r"); $i = 0; while (($row = fgetcsv($fp, 0, "\t")) !== false) { if (count($row) == 1 || preg_match('/^#/', $row[0])) { continue; } $i++; $item = call_user_func(array('GeoName', $map), $row, $i); if ($item) { $items[] = $item; } } echo sprintf("-> Writing %s\n", $file); $out = PhpArray::generate(compact('src', 'items')); file_put_contents(ROOT . '/' . $file, $out); }
#!/usr/bin/php <?php require_once 'libs/php_array.php'; $src = 'http://www.mimetype.org/'; $html = file_get_contents($src); $regex = '/<tr><td>([^<]+)<\\/td><td>([^<]+)<\\/td><\\/tr>/'; preg_match_all($regex, $html, $matches, PREG_SET_ORDER); $items = array(); foreach ($matches as $match) { list(, $mimeType, $extensions) = $match; $extensions = preg_split('/\\s+/', $extensions); foreach ($extensions as $ext) { $items[$ext] = $mimeType; } } $out = PhpArray::generate(compact('src', 'items')); file_put_contents(ROOT . '/extensions.php', $out); $items = array_flip($items); $out = PhpArray::generate(compact('src', 'items')); file_put_contents(ROOT . '/mime_types.php', $out);