1 && false !== strpos( "=+-@\t\r'", $value[1] ) ) ) ) { return "'" . $value; } return $value; } /** * Protect a row. * * @param array $cells Cells. * @return string[] */ public static function row( array $cells ): array { return array_map( array( __CLASS__, 'cell' ), array_values( $cells ) ); } /** * Write one CSV record to a stream with the same dialect the reader expects (no escape character, "" for a quote). * Every cell is quoted: a spreadsheet whose list separator is another character (";" in many locales) would split an * unquoted "x;=FORMULA" cell and run the part after the separator. * * @param resource $stream Stream. * @param array $cells Cells (already protected where needed). * @param string $delim Delimiter. * @return void */ public static function put( $stream, array $cells, string $delim = ',' ): void { $out = array(); foreach ( $cells as $cell ) { $out[] = '"' . str_replace( '"', '""', (string) $cell ) . '"'; } fwrite( $stream, implode( $delim, $out ) . "\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite } }