Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Created May 15, 2024 09:37
Show Gist options
  • Save catwhocode/1cb64c62446a85387c909b382104786c to your computer and use it in GitHub Desktop.
Save catwhocode/1cb64c62446a85387c909b382104786c to your computer and use it in GitHub Desktop.
Read CSV
<?php
// Open the file for reading
if (($myfile = fopen("myfile.csv", "r")) !== FALSE) {
// Convert each line into the local $data variable
while (($data = fgetcsv($myfile, 1000, ",")) !== FALSE) {
// Read the data from a single line
$nama = $data[0];
$nik = $data[1];
$unit_kerja = $data[2];
$email = $data[3];
$is_active = 1;
$group_id = 6; // $data[4];
$gapok = $data[5];
echo $nama . ' | ' . $nik . ' | ' . $unit_kerja . "\n";
}
// Close the file
fclose($myfile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment