Things You'll Need:
- PHP
-
Step 1
Open a blank text file in any text editor.
-
Step 2
Start your php script with the line: <?php
-
Step 3
Set the starting row number with the line: $row = 1;
-
Step 4
Open the .csv file to read only with the line: $file=fopen("example.csv", "r");
-
Step 5
Start the while loop that will run through the data and place each line into an array:
while (($data = fgetcsv($file, 8000, ",")) !== FALSE) { -
Step 6
Count the number of fields in each line: $num = count($data);
-
Step 7
Start a for loop to print out the data to the screen: for ($x=0; $x < $num; $x++) {
-
Step 8
Print the data to the screen and close the for and while loops: echo $data[$c] ."\n";}}
-
Step 9
Close the file with the line: fclose($file);
-
Step 10
Close the php script: ?>
-
Step 11
Save the script with the ".php" extension. The entire script will look like this:
<?php
$row = 1;
$file = fopen("example.csv", "r");
while (($data = fgetcsv($file, 8000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "\n";}}
fclose($file);
?>









