PHP offers a way to parse a stream handle, but not way to parse just a string. Here’s a simple/lazy way to parse a single CSV line in PHP:
function parseCSV($str, $delimiter = ',', $enclosure = '"',
$len = 4096)
{
$fh = fopen('php://memory', 'rw');
fwrite($fh, $str);
rewind($fh);
$result = fgetcsv( $fh, $len, $delimiter, $enclosure );
fclose($fh);
return $result;
}
No related posts.