ja*******@hotmail.com (Joe Randstein) wrote in message news:<f7**************************@posting.google. com>...
Hi!
I get CSV-data from a post-request. How can I work on that?
Currently I save the data to a temp-file, then read it back with
fgetcsv and then delete the temp-file. That works, but I don't really
like it ...
Is there a way to directly parse the CSV data from the string (with
php-4.2.4)
IMHO, that is the most dependable way. Put the operation in a function
like:
<?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_ use the csv_explode() function found at the usernotes of
<http://in2.php.net/explode> Hope, my version will do the work
properly.
--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com