wp_kses_normalize_entities

函数
wp_kses_normalize_entities ( $string, $context = 'html' )
参数
  • (string) $string Content to normalize entities.
    Required:
  • (string) $context Context for normalization. Can be either 'html' or 'xml'. Default 'html'.
    Required:
    Default: 'html'
返回值
  • (string) Content with normalized entities.
定义位置
相关方法
wp_kses_named_entitieswp_kses_decode_entitieswp_kses_xml_named_entitieswp_kses_js_entitieswp_normalize_site_data
引入
1.0.0
弃用
-

wp_kses_normalize_entities: 这个函数用来将一个字符串中的HTML实体规范化为相应的UTF-8字符。

转换和修复HTML实体。

这个函数将HTML实体规范化。它将把`AT&T`转换为正确的`AT&T`,`:`转换为`:`,`&#XYZZY;`转换为`&#XYZZY;`,以此类推。

当`$context`被设置为’xml’时,HTML实体被转换为其代码点。 例如,`AT&T…&#XYZZY;`被转换为`AT&T…&#XYZZY;`。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常见问题

FAQs
查看更多 >