Getting CSV data from a string
If you have a small CSV file stored in a string, and don't want to implement your own CSV parser or read the data into and out of a stream using fgetcsv, str_getcsv is the perfect function for the job.
For example:
$rows = explode("\r\n", $csv);
$headers = str_getcsv(trim(array_shift($rows)));
foreach( $rows as $row )
{
$row = str_getcsv(trim($row));
//Processing here
}
You can find the docs on this useful function here:
http://php.net/manual/function.str-getcsv.php
Written by David North
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#