wp_kses_no_null( string $content, array $options = null ): string

Removes any invalid control characters in a text string.

Description

Also removes any instance of the \0 string.

Parameters

$contentstringrequired
Content to filter null characters from.
$optionsarrayoptional
Set 'slash_zero' => 'keep' when '' is allowed. Default is 'remove'.

Default:null

Return

string Filtered content.

Source

function wp_kses_no_null( $content, $options = null ) {
	if ( ! isset( $options['slash_zero'] ) ) {
		$options = array( 'slash_zero' => 'remove' );
	}

	$content = preg_replace( '/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $content );
	if ( 'remove' === $options['slash_zero'] ) {
		$content = preg_replace( '/\\\\+0+/', '', $content );
	}

	return $content;
}

Changelog

VersionDescription
1.0.0Introduced.

User Contributed Notes

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