Press enter to see results or esc to cancel.

Read a CSV file using PHP

In this video,I have shown how to read a CSV file using PHP.
1. Below code can be used to read the CSV file and show it exactly as a table in the PHP page.

echo '<table border="1">';
$start_row = 1;
if (($csv_file = fopen("F:\\readcsv\\country.csv", "r")) !== FALSE) {
  while (($read_data = fgetcsv($csv_file, 1000, ",")) !== FALSE) {
    $column_count = count($read_data);
	echo '<tr>';
    for ($c=0; $c < $column_count; $c++) {
        echo "<td>".$read_data[$c] . "</td>";
	echo '</tr>';
echo '</table>';

2. The CSV file we read using the above code is shown below.

3. After the file is read, It will be shown as below.



Leave a Comment