WC_CSV_Exporter::fputcsv( resource $buffer, array $export_row )

Write to the CSV file, ensuring escaping works across versions of PHP.


Description Description

PHP 5.5.4 uses ‘\’ as the default escape character. This is not RFC-4180 compliant. \0 disables the escape character.

See also See also


Top ↑

Parameters Parameters

$buffer

(Required) Resource we are writing to.

$export_row

(Required) Row to export.


Top ↑

Source Source

File: includes/export/abstract-wc-csv-exporter.php

	protected function fputcsv( $buffer, $export_row ) {

		if ( version_compare( PHP_VERSION, '5.5.4', '<' ) ) {
			ob_start();
			$temp = fopen( 'php://output', 'w' ); // @codingStandardsIgnoreLine
    		fputcsv( $temp, $export_row, $this->get_delimiter(), '"' ); // @codingStandardsIgnoreLine
			fclose( $temp ); // @codingStandardsIgnoreLine
			$row = ob_get_clean();
			$row = str_replace( '\\"', '\\""', $row );
			fwrite( $buffer, $row ); // @codingStandardsIgnoreLine
		} else {
			fputcsv( $buffer, $export_row, $this->get_delimiter(), '"', "\0" ); // @codingStandardsIgnoreLine
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.9.0
3.4.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.