Well, explode, then loop through....

<?php
// Get the contents into a varialbe [possibly file_get_contents('some_file.csv') ]
// We'll say the contents of the CSV are placed into the variable "$contents"

// Break each line up
$lines = explode("\n", $contents);

// Now, loop through each line, and make a new row...
for($i=0; $i<count($lines); $i++)
{
    $rows .= '<tr>';
    $items = explode(","$lines[$i]);

foreach($items as $item)
{
    $rows .= ($i == 0)?'<th>':'<td>';
    $rows .= trim($item);
    $rows .= ($i == 0)?'</th>':'</td>';
}

$rows .= '</tr>';
}

// Then just echo out the table
echo '<table>'.$rows.'</table>';

?>

~Brett

EDIT:
Just ran a quick test on my local server, works perfectly. Just need to add your own formatting to the table and you're set to go!!
[right]Nov. 30 @ 12:05 PM EST[/right]

Excellent, bpat1434. It looks very good, and very grateful to you.

Nice website, by the by. Looks rather like the fjords in New Zealand in your photo, but perhaps it's closer to your own home?

Cheers and thank you.

    13 years later

    I know I'm really late to this party, but I built a quick little app around a process that reads in the CSV file via PHP, then formats it as output.

    	public function get_data() {
    		// pull from a local file
    		$row = 0;
    		$result = array();
    
    	try {
    		if (($handle = fopen($this->data_source, "r")) !== FALSE) {
    			while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    				$num = count($data);
    				for ($c=0; $c < $num; $c++) {
    					$result[$row][$c] = $data[$c];
    				}
    				$row++;
    			}
    			fclose($handle);
    		}
    	} 
    	catch (Exception $e) {
    		// nothing here
    	}
    	return $result;
    }
    

    (Added [code]...[/code] tags ~ Mod.)

      14 days later
      14 days later

      You know it be nice if you can once in a while click Mark Solve on some of the threads you posted. It's just that sometimes you just double a same questions because you can't add something or can't modify it.

      You need to used this function:

      to pull the csv file on to the webpage.

        Write a Reply...