A WordPress-centric search engine for devs and theme authors



wp_kses_normalize_entities ›

Since1.0.0
Deprecatedn/a
wp_kses_normalize_entities ( $string, $context = 'html' )
Parameters: (2)
  • (string) $string Content to normalize entities.
    Required: Yes
  • (string) $context Context for normalization. Can be either 'html' or 'xml'. Default 'html'.
    Required: No
    Default: 'html'
Returns:
  • (string) Content with normalized entities.
Defined at:
Codex:
Change Log:
  • 5.5.0

Converts and fixes HTML entities.

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;.


Source

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;
}