$cells Cells. * @return string */ public static function line( array $cells ): string { return implode( ',', array_map( array( self::class, 'cell' ), $cells ) ) . "\r\n"; } /** * One cell: made safe, then quoted when it needs it. * * @since 0.1.0 * * @param scalar|null $value Cell value. * @return string */ public static function cell( $value ): string { $text = null === $value ? '' : (string) ( is_bool( $value ) ? (int) $value : $value ); if ( '' !== $text && ! is_numeric( $text ) && 1 === preg_match( '/^[=+\-@\t\r]/', $text ) ) { $text = "'" . $text; } if ( preg_match( '/[",\r\n]/', $text ) ) { $text = '"' . str_replace( '"', '""', $text ) . '"'; } return $text; } }