Este código fue extraído de otro blog que ha sido probado y funciona correctamente.

“This is a snippet of code that I had posted on another of my websites and in doing some cleanup it really fits better here.

I spent last evening working on a Comma Separated Values (CSV) list of titles for a project I’m working on. Below is a snippet of code I worked with. The first method from the PHP Cookbook suggests using fgetcsv(). That woks pretty well but the native function in PHP doesn’t handle values (fields) that contain separators (commas) very well and doesn’t have the concept of multiple values being delimited by a different delimiter within a field. So I whipped up the parser that comes second in the example below.”


<?php
$fp = fopen('filename','r') or die("can't open file");
print ('
\n');
while($csv_line = fgetcsv($fp,1024, ",", "\"")) {
print '
');
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
print '

';
}
print ("
\n");
}
print ("
'. str_replace (";\"", " ", $csv_line[$i]).'
\n");*/ fclose($fp) or die("can't close file"); $bas = file_get_contents ("filename"); print ("
\n");

$lines = explode("\n", $bas);

foreach ($lines as $line) {

print("
");
$line = ltrim($line, "\"");
$line = rtrim($line, "\"");
$line = rtrim($line);
$out = str_replace("\";\"", "
", $line);
$out = str_replace("\",\"", "
");
print ("
\n");
};
print ("
", $out);

print ("
") . $out . "
\n");
?>