wp_kses_normalize_entities() WordPress Function

The wp_kses_normalize_entities() function is used to normalize entities in an HTML string. This function is used by the kses HTML filtering library.

wp_kses_normalize_entities( string $string, string $context = 'html' ) #

Converts and fixes HTML entities.


Description

This function normalizes HTML entities. It will convert AT&T to the correct AT&T, : to :, &#XYZZY; to &#XYZZY; and so on.

When $context is set to ‘xml’, HTML entities are converted to their code points. For example, AT&T…&#XYZZY; is converted to AT&T…&#XYZZY;.


Top ↑

Parameters

$string

(string)(Required)Content to normalize entities.

$context

(string)(Optional)Context for normalization. Can be either 'html' or 'xml'.

Default value: 'html'


Top ↑

Return

(string) Content with normalized entities.


Top ↑

Source

File: wp-includes/kses.php

function wp_kses_normalize_entities( $string, $context = 'html' ) {
	// Disarm all entities by converting & to &
	$string = str_replace( '&', '&', $string );

	// Change back the allowed entities in our list of allowed entities.
	if ( 'xml' === $context ) {
		$string = preg_replace_callback( '/&([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_xml_named_entities', $string );
	} else {
		$string = preg_replace_callback( '/&([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $string );
	}
	$string = preg_replace_callback( '/&#(0*[0-9]{1,7});/', 'wp_kses_normalize_entities2', $string );
	$string = preg_replace_callback( '/&#[Xx](0*[0-9A-Fa-f]{1,6});/', 'wp_kses_normalize_entities3', $string );

	return $string;
}


Top ↑

Changelog

Changelog
VersionDescription
5.5.0Added $context parameter.
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.