On this page
wp_kses_normalize_entities( string $string, string $context = 'html' ): string
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;.
Parameters
$stringstring Required-
Content to normalize entities.
$contextstring Optional-
Context for normalization. Can be either
'html'or'xml'.
Default'html'.Default:
'html'
Return
string Content with normalized entities.
Source
File: wp-includes/kses.php. View all references
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;
}
Related
Used By
| Used By | Description |
|---|---|
| esc_url() wp-includes/formatting.php | Checks and cleans a URL. |
| _wp_specialchars() wp-includes/formatting.php | Converts a number of special characters into their HTML entities. |
| wp_kses() wp-includes/kses.php | Filters text content and strips out disallowed HTML. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_kses_normalize_entities