wpseek.com
WordPress开发者和主题制作者的搜索引擎



wp_kses_normalize_entities › WordPress Function

Since1.0.0
已弃用n/a
wp_kses_normalize_entities ( $content, $context = 'html' )
参数: (2)
  • (string) $content Content to normalize entities.
    Required: Yes
  • (string) $context Context for normalization. Can be either 'html' or 'xml'. Default 'html'.
    Required: No
    默认: 'html'
返回:
  • (string) Content with normalized entities.
定义在:
文档:
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;.


源码

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

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

	return $content;
}