index.php 607 B

1234567891011121314151617181920
  1. <?php
  2. $row = 1;
  3. if (($handle = fopen("dbip-country-lite-2019-05.csv", "r")) !== FALSE) {
  4. while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  5. $num = count($data);
  6. echo "<p> $num fields in line $row: <br /></p>\n";
  7. $row++;
  8. for ($c=0; $c < $num; $c++) {
  9. echo $data[$c] . "<br />\n";
  10. }
  11. if (strpos($data[0], '.') !== false) {
  12. $fp = fopen(explode(".",$data[0])[0].".csv", 'a');
  13. }else{
  14. $fp = fopen(explode(":",$data[0])[0].".csv", 'a');
  15. }
  16. fwrite($fp, $data[0].",".$data[1].",".$data[2]."\r\n");
  17. fclose($fp);
  18. }
  19. fclose($handle);
  20. }