| @@ 550-573 (lines=24) @@ | ||
| 547 | * @param string $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value | |
| 548 | * @return void | |
| 549 | */ | |
| 550 | 	private function fputcsv2 ($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = FALSE) { | |
| 551 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards | |
| 552 | $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); | |
| 553 | $enclosure = apply_filters( 'FHEE__EE_CSV__fputcsv2__enclosure', $enclosure ); | |
| 554 | ||
| 555 | $delimiter_esc = preg_quote($delimiter, '/'); | |
| 556 | $enclosure_esc = preg_quote($enclosure, '/'); | |
| 557 | ||
| 558 | $output = array(); | |
| 559 | 		foreach ($row as $field_value) { | |
| 560 | 			if(is_object($field_value) || is_array($field_value)){ | |
| 561 | $field_value = serialize($field_value); | |
| 562 | } | |
| 563 | 			if ($field_value === null && $mysql_null) { | |
| 564 | $output[] = 'NULL'; | |
| 565 | continue; | |
| 566 | } | |
| 567 | ||
| 568 | 			$output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? | |
| 569 | ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; | |
| 570 | } | |
| 571 | ||
| 572 | fwrite($fh, join($delimiter, $output) . PHP_EOL); | |
| 573 | } | |
| 574 | ||
| 575 | ||
| 576 | ||
| @@ 97-120 (lines=24) @@ | ||
| 94 | * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value | |
| 95 | * @return string of text for teh csv file | |
| 96 | */ | |
| 97 | 	public static function get_csv_row ( array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false ) { | |
| 98 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards | |
| 99 | $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); | |
| 100 | $enclosure = apply_filters( 'FHEE__EE_CSV__fputcsv2__enclosure', $enclosure ); | |
| 101 | ||
| 102 | $delimiter_esc = preg_quote($delimiter, '/'); | |
| 103 | $enclosure_esc = preg_quote($enclosure, '/'); | |
| 104 | ||
| 105 | $output = array(); | |
| 106 | 		foreach ($row as $field_value) { | |
| 107 | 			if(is_object($field_value) || is_array($field_value)){ | |
| 108 | $field_value = serialize($field_value); | |
| 109 | } | |
| 110 | 			if ($field_value === null && $mysql_null ) { | |
| 111 | $output[] = 'NULL'; | |
| 112 | continue; | |
| 113 | } | |
| 114 | ||
| 115 | 			$output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? | |
| 116 | ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; | |
| 117 | } | |
| 118 | ||
| 119 | return implode($delimiter, $output) . PHP_EOL; | |
| 120 | } | |
| 121 | ||
| 122 | ||
| 123 | ||