<?php

#$data=file_get_contents("./worldcities.cvs");

$file="worldcities.csv";
$fh=fopen($file,'r');
$data=fread($fh,filesize($file));
fclose($fh);

$lines=explode("\n",$data);
$idx=0;
$csv="\n"; // skip first line as original
for($i=1;$i<count($lines);$i++) {
    $line=explode(",",$lines[$i]);
    $pop=intval(str_replace("\"","",$line[9]));

    if($pop>250000) {
        $name=str_replace("\"","",$line[1]);
        $lat=intval(str_replace("\"","",$line[2]));
        $lon=intval(str_replace("\"","",$line[3]));
        $idx++;

        //echo "idx: ".$idx.") name: ".$name.", lat: ".$lat.", lon: ".$lon.", pop: ".$pop."<br />\n";

        // mini csv
        $csv.="\"\", \"".$name."\", \"".$lat."\", \"".$lon."\", \"\", \"\", \"\", \"\", \"\", \"".$pop."\",\"\"\n"; 
    }
}

echo nl2br($csv);

$nfile="./worldcities.small.csv";
$fh=fopen($nfile,'w');
fwrite($fh,$csv);
fclose($fh);

//echo $data;

exit;

?>
