str_putcsv

The Ninja Forms str putcsv function.

Description

str_putcsv( $array, (string) $delimiter = ',', (string) $enclosure = '"', $terminator = ' 
' ); 

Parameters (4)

0. $array
The array.
1. $delimiter — Optional. (string) => ','
The delimiter.
2. $enclosure — Optional. (string) => '"'
The enclosure.
3. $terminator — Optional. (string) => ' '
The terminator.

Usage

  1. if ( !function_exists( 'str_putcsv' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/admin/admin.php'; 
  3.  
  4. // The array. 
  5. $array = null; 
  6.  
  7. // The delimiter. 
  8. $delimiter = ','; 
  9.  
  10. // The enclosure. 
  11. $enclosure = '"'; 
  12.  
  13. // The terminator. 
  14. $terminator = ' 
  15. '; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = str_putcsv($array, $delimiter, $enclosure, $terminator); 
  19.  

Defined (1)

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

/deprecated/includes/admin/admin.php  
  1. function str_putcsv( $array, $delimiter = ', ', $enclosure = '"', $terminator = "\n" ) { 
  2. // First convert associative array to numeric indexed array 
  3. $workArray = array(); 
  4. foreach ($array as $key => $value) { 
  5. $workArray[] = $value; 
  6.  
  7. $returnString = ''; # Initialize return string 
  8. $arraySize = count( $workArray ); # Get size of array 
  9.  
  10. for ( $i=0; $i<$arraySize; $i++ ) { 
  11. // Nested array, process nest item 
  12. if ( is_array( $workArray[$i] ) ) { 
  13. $returnString .= str_putcsv( $workArray[$i], $delimiter, $enclosure, $terminator ); 
  14. } else { 
  15. switch ( gettype( $workArray[$i] ) ) { 
  16. // Manually set some strings 
  17. case "NULL": $_spFormat = ''; break; 
  18. case "boolean": $_spFormat = ($workArray[$i] == true) ? 'true': 'false'; break; 
  19. // Make sure sprintf has a good datatype to work with 
  20. case "integer": $_spFormat = '%i'; break; 
  21. case "double": $_spFormat = '%0.2f'; break; 
  22. case "string": $_spFormat = '%s'; $workArray[$i] = str_replace("$enclosure", "$enclosure$enclosure", $workArray[$i]); break; 
  23. // Unknown or invalid items for a csv - note: the datatype of array is already handled above, assuming the data is nested 
  24. case "object": 
  25. case "resource": 
  26. default: $_spFormat = ''; break; 
  27. $returnString .= sprintf('%2$s'.$_spFormat.'%2$s', $workArray[$i], $enclosure); 
  28. $returnString .= ($i < ($arraySize-1)) ? $delimiter : $terminator; 
  29. // Done the workload, return the output information 
  30. return $returnString;