返回介绍

wp_specialchars_decode()

发布于 2017-09-11 12:57:21 字数 5206 浏览 881 评论 0 收藏 0

wp_specialchars_decode( string $string,  string|int $quote_style = ENT_NOQUOTES )

Converts a number of HTML entities into their special characters.


description

Specifically deals with: &, <, >, ", and ‘.

$quote_style can be set to ENT_COMPAT to decode " entities, or ENT_QUOTES to do both " and ‘. Default is ENT_NOQUOTES where no quotes are decoded.


参数

$string

(string) (Required) The text which is to be decoded.

$quote_style

(string|int) (Optional) Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES.

Default value: ENT_NOQUOTES


返回值

(string) The decoded text without HTML entities.


源代码

File: wp-includes/formatting.php

function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) {
	$string = (string) $string;

	if ( 0 === strlen( $string ) ) {
		return '';
	}

	// Don't bother if there are no entities - saves a lot of processing
	if ( strpos( $string, '&' ) === false ) {
		return $string;
	}

	// Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value
	if ( empty( $quote_style ) ) {
		$quote_style = ENT_NOQUOTES;
	} elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
		$quote_style = ENT_QUOTES;
	}

	// More complete than get_html_translation_table( HTML_SPECIALCHARS )
	$single = array( '''  => '\'', ''' => '\'' );
	$single_preg = array( '/&#0*39;/'  => ''', '/&#x0*27;/i' => ''' );
	$double = array( '&quot;' => '"', '"'  => '"', '"' => '"' );
	$double_preg = array( '/&#0*34;/'  => '"', '/&#x0*22;/i' => '"' );
	$others = array( '&lt;'   => '<', '<'  => '<', '&gt;'   => '>', '>'  => '>', '&amp;'  => '&', '&'  => '&', '&' => '&' );
	$others_preg = array( '/&#0*60;/'  => '<', '/&#0*62;/'  => '>', '/&#0*38;/'  => '&', '/&#x0*26;/i' => '&' );

	if ( $quote_style === ENT_QUOTES ) {
		$translation = array_merge( $single, $double, $others );
		$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
	} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
		$translation = array_merge( $double, $others );
		$translation_preg = array_merge( $double_preg, $others_preg );
	} elseif ( $quote_style === 'single' ) {
		$translation = array_merge( $single, $others );
		$translation_preg = array_merge( $single_preg, $others_preg );
	} elseif ( $quote_style === ENT_NOQUOTES ) {
		$translation = $others;
		$translation_preg = $others_preg;
	}

	// Remove zero padding on numeric entities
	$string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );

	// Replace characters according to translation table
	return strtr( $string, $translation );
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Used By

  • wp-login.php: retrieve_password()
  • wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::send_email()
  • wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::send_debug_email()
  • wp-admin/includes/ms.php: update_option_new_admin_email()
  • wp-admin/includes/ms.php: send_confirmation_on_profile_email()
  • wp-admin/includes/user.php: admin_created_user_email()
  • wp-includes/pluggable.php: wp_password_change_notification()
  • wp-includes/pluggable.php: wp_new_user_notification()
  • wp-includes/pluggable.php: wp_notify_postauthor()
  • wp-includes/pluggable.php: wp_notify_moderator()
  • wp-includes/user.php: wp_update_user()
  • wp-includes/ms-functions.php: wpmu_welcome_user_notification()
  • wp-includes/ms-functions.php: wpmu_welcome_notification()
  • wp-includes/ms-functions.php: wpmu_signup_blog_notification()
  • wp-includes/ms-functions.php: wpmu_signup_user_notification()
  • Show 10 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文