motolanix1
asked on
Display CSV file data using PHP
Hi There,
I have written the code below to read am reading the contents of a CSV file. The content in the CSV file has three colums with data and multiple rows:
content1, content2, content3
content1, content2, content3
content1, content2, content3
I need to display this as a table in a webpage where content1, content2 and content3 would be in their own cell. When displayed in the webpage there should be three rows. Any suggestions on how i can get this done?
See code below. Speedy response is very much appreciated.
$dir_name = "C:/apache/htdocs/E-Books. txt";
$fh = fopen($dir_name, "r");
$row = 1;
while(($data = fgetcsv($fh, 1000, ",")) !== FALSE)
{
$num = count($data); // count the # of lines that exist
$row++; //increment the row variable to the next line
//output current line to the screen.
for ($i=0; $i < $num; $i++)
{
echo $data[$i]."\n";
}
}
//close file handler and delete file
fclose($fh);
I have written the code below to read am reading the contents of a CSV file. The content in the CSV file has three colums with data and multiple rows:
content1, content2, content3
content1, content2, content3
content1, content2, content3
I need to display this as a table in a webpage where content1, content2 and content3 would be in their own cell. When displayed in the webpage there should be three rows. Any suggestions on how i can get this done?
See code below. Speedy response is very much appreciated.
$dir_name = "C:/apache/htdocs/E-Books.
$fh = fopen($dir_name, "r");
$row = 1;
while(($data = fgetcsv($fh, 1000, ",")) !== FALSE)
{
$num = count($data); // count the # of lines that exist
$row++; //increment the row variable to the next line
//output current line to the screen.
for ($i=0; $i < $num; $i++)
{
echo $data[$i]."\n";
}
}
//close file handler and delete file
fclose($fh);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.