WP_CLI\Utils

escape_csv_value()WP-CLI 1.0

Escape a value for CSV output.

Values that start with the following characters are escaping with a single quote: =, +, -, @, TAB (0x09) and CR (0x0D).

No Hooks.

Returns

String. Escaped value.

Usage

escape_csv_value( $value );
$value(string) (required)
Value to escape.

escape_csv_value() code WP-CLI 2.13.0-alpha

function escape_csv_value( $value ) {
	if ( null === $value ) {
		return '';
	}

	// Convert to string if not already
	$value = (string) $value;

	if (
		in_array(
			substr( $value, 0, 1 ),
			[ '=', '+', '-', '@', "\t", "\r" ],
			true
		)
	) {
		return "'{$value}";
	}

	return $value;
}