Beispiel #1
0
 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);
 }
Beispiel #2
0
/**
 * @param $arr
 * @return PhpArray
 * @throws \PgBabylon\Exceptions\InvalidValue
 */
function PhpArray($arr)
{
    $a = new PhpArray(null);
    $a->setUsingPhpValue($arr);
    return $a;
}
Beispiel #3
0
#!/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);