"Kevin Lin" <ke***@wx3REMOVE4SPAM.com> wrote in message news:<hdKod.557418$mD.522470@attbi_s02>...
Hello all,
Anyone know of a way to call fgetcsv and fputcsv using a string rather than
a resource? (i.e.., parse a comma delimited string without writing it first
to a file.)
IMHO, the most dependable way is to use existing fgetcsv along with
a temporary file:
<?php
function ParseCSVString($str, $delim=',')
{
//write the CSV string to a temporary file so that fgetcsv() can be
used to process...
$fp = tmpfile();
fwrite($fp, $str);
rewind($fp); //rewind to process CSV
$csv_length = strlen($str);
$data_arr = fgetcsv($fp, $csv_length, $delim);
fclose($fp); //clean up temp file
return $data_arr; //return the array
}
?>
Or may use csv_explode() found at <http://in.php.net/explode#37004>
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com