<?php
$row = 1;
if (($handle = fopen("dbip-country-lite-2019-05.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
		if (strpos($data[0], '.') !== false) {
			$fp = fopen(explode(".",$data[0])[0].".csv", 'a');
		}else{
			$fp = fopen(explode(":",$data[0])[0].".csv", 'a');
		}
		fwrite($fp, $data[0].",".$data[1].",".$data[2]."\r\n");
		fclose($fp);
    }
    fclose($handle);
}