stats_str_getcsv

Rather than parsing the csv and its special cases, we create a new file and do fgetcsv on it.

Description

stats_str_getcsv( $csv ); 

Parameters (1)

0. $csv
The csv.

Usage

  1. if ( !function_exists( 'stats_str_getcsv' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/stats.php'; 
  3.  
  4. // The csv. 
  5. $csv = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = stats_str_getcsv($csv); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/stats.php  
  1. function stats_str_getcsv( $csv ) { 
  2. if ( function_exists( 'str_getcsv' ) ) { 
  3. $lines = str_getcsv( $csv, "\n" ); 
  4. return array_map( 'str_getcsv', $lines ); 
  5. if ( !$temp = tmpfile() ) // tmpfile() automatically unlinks 
  6. return false; 
  7.  
  8. $data = array(); 
  9.  
  10. fwrite( $temp, $csv, strlen( $csv ) ); 
  11. fseek( $temp, 0 ); 
  12. while ( false !== $row = fgetcsv( $temp, 2000 ) ) 
  13. $data[] = $row; 
  14. fclose( $temp ); 
  15.  
  16. return $data;