<?php 

$xmin 
0;
$ymin 0;
$xmax 999;
$ymax 999;

$types = array();
$types[0] = '';
$types[1] = '';
$types[2] = '';
$types[3] = '';
$types[8] = 'mountain';
$types[9] = 'mountain';
$types[10] = 'mountain';
$types[11] = 'mountain';
$types[12] = 'lake';
$types[16] = 'forest';
$types[17] = 'forest';
$types[18] = 'forest';
$types[19] = 'forest';
$types[20] = 'forest';
$types[21] = 'forest';
$types[22] = 'forest';
$types[23] = 'forest';
$types[24] = 'forest';
$types[25] = 'forest';
$types[26] = 'forest';
$types[27] = 'forest';
$types[28] = 'forest';
$types[29] = 'forest';
$types[30] = 'forest';
$types[31] = 'forest';

$f fopen("world.dat","r");

for(
$y $ymin$y <= $ymax$y++)
{
    for(
$x $xmin$x <= $xmax$x++)
    {
        
//fseek($f, $y*1000+$x); //not need if exporting all data

        
$type ord(fgetc($f));
        if(isset(
$types[$type]))
        {
            if(
$types[$type])
            {
                echo 
"REPLACE INTO terrain SET x = '{$x}', y = '{$y}', terrain = '{$types[$type]}';\n";
            }
            else
            {
                
//ignore grass
            
}
        }
        else
        {
            die(
"\n\nUnknowned type: {$type}\n");
        }
    }
    echo 
"\n";
}
fclose($f); 
?>