返回介绍

esc_html()

发布于 2017-09-10 22:27:36 字数 13851 浏览 1157 评论 0 收藏 0

esc_html( string $text )

Escaping for HTML blocks.


description


参数

$text

(string) (Required)


返回值

(string)


源代码

File: wp-includes/formatting.php

function esc_html( $text ) {
	$safe_text = wp_check_invalid_utf8( $text );
	$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
	/**
	 * Filters a string cleaned and escaped for output in HTML.
	 *
	 * Text passed to esc_html() is stripped of invalid or special characters
	 * before output.
	 *
	 * @since 2.8.0
	 *
	 * @param string $safe_text The text after it has been escaped.
 	 * @param string $text      The text prior to being escaped.
	 */
	return apply_filters( 'esc_html', $safe_text, $text );
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: esc_html
  • wp-includes/formatting.php: wp_check_invalid_utf8()
  • wp-includes/formatting.php: _wp_specialchars()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/widgets/class-wp-widget-media.php: WP_Widget_Media::render_control_template_scripts()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::print_post_type_container()
  • wp-admin/includes/class-wp-ajax-upgrader-skin.php: WP_Ajax_Upgrader_Skin::get_error_messages()
  • wp-admin/includes/ms.php: network_edit_site_nav()
  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_plugin()
  • wp-admin/includes/ajax-actions.php: wp_ajax_install_theme()
  • wp-admin/includes/ajax-actions.php: wp_ajax_update_theme()
  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_theme()
  • wp-admin/includes/ajax-actions.php: wp_ajax_install_plugin()
  • wp-includes/embed.php: the_embed_site_title()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::start_dynamic_sidebar()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::end_dynamic_sidebar()
  • wp-includes/embed.php: _oembed_create_xml()
  • wp-includes/general-template.php: wp_get_document_title()
  • wp-includes/customize/class-wp-customize-nav-menu-location-control.php: WP_Customize_Nav_Menu_Location_Control::render_content()
  • wp-includes/customize/class-wp-customize-nav-menu-setting.php: WP_Customize_Nav_Menu_Setting::sanitize()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::available_items_template()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::enqueue_scripts()
  • wp-includes/customize/class-wp-customize-new-menu-section.php: WP_Customize_New_Menu_Section::render()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_title()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_default()
  • wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::handle_row_actions()
  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_default()
  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_title()
  • wp-admin/includes/ajax-actions.php: wp_ajax_update_plugin()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::html()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::post_formats_html()
  • wp-includes/link-template.php: _navigation_markup()
  • wp-includes/date.php: WP_Date_Query::validate_date_values()
  • wp-includes/class-wp-customize-section.php: WP_Customize_Section::json()
  • wp-includes/l10n.php: wp_dropdown_languages()
  • wp-admin/includes/ajax-actions.php: wp_ajax_parse_embed()
  • wp-admin/includes/translation-install.php: wp_install_language_form()
  • wp-signup.php: signup_user()
  • wp-admin/includes/class-wp-upgrader.php: WP_Upgrader::fs_connect()
  • wp-admin/includes/class-wp-screen.php: WP_Screen::render_screen_meta()
  • wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::no_items()
  • wp-admin/includes/deprecated.php: wp_dropdown_cats()
  • wp-admin/includes/theme-install.php: install_themes_dashboard()
  • wp-admin/includes/class-bulk-upgrader-skin.php: Bulk_Upgrader_Skin::error()
  • wp-admin/includes/class-wp-upgrader-skin.php: WP_Upgrader_Skin::error()
  • wp-admin/includes/ms.php: mu_dropdown_languages()
  • wp-admin/includes/ms.php: new_user_email_admin_notice()
  • wp-admin/includes/misc.php: admin_color_scheme_picker()
  • wp-admin/includes/deprecated.php: wp_dashboard_plugins_output()
  • wp-admin/includes/dashboard.php: wp_dashboard_browser_nag()
  • wp-admin/includes/dashboard.php: wp_dashboard_recent_drafts()
  • wp-admin/includes/dashboard.php: _wp_dashboard_recent_comments_row()
  • wp-admin/includes/class-wp-plugin-install-list-table.php: WP_Plugin_Install_List_Table::display_rows()
  • wp-admin/includes/class-walker-category-checklist.php: Walker_Category_Checklist::start_el()
  • wp-admin/includes/template.php: _draft_or_post_title()
  • wp-admin/includes/template.php: get_inline_data()
  • wp-admin/includes/template.php: meta_form()
  • wp-admin/includes/template.php: parent_dropdown()
  • wp-admin/includes/template.php: do_accordion_sections()
  • wp-admin/includes/template.php: wp_popular_terms_checklist()
  • wp-admin/includes/template.php: wp_link_category_checklist()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::single_row()
  • wp-admin/includes/media.php: media_upload_type_form()
  • wp-admin/includes/media.php: media_upload_library_form()
  • wp-admin/includes/media.php: attachment_submitbox_metadata()
  • wp-admin/includes/media.php: get_media_item()
  • wp-admin/includes/media.php: media_upload_form()
  • wp-admin/includes/media.php: wp_media_upload_handler()
  • wp-admin/includes/post.php: get_sample_permalink_html()
  • wp-admin/includes/post.php: _wp_post_thumbnail_html()
  • wp-admin/includes/post.php: _admin_notice_post_locked()
  • wp-admin/includes/post.php: get_default_post_to_edit()
  • wp-admin/includes/ajax-actions.php: wp_ajax_wp_fullscreen_save_post()
  • wp-admin/includes/ajax-actions.php: wp_ajax_inline_save()
  • wp-admin/includes/ajax-actions.php: wp_ajax_find_posts()
  • wp-admin/includes/ajax-actions.php: wp_ajax_add_link_category()
  • wp-admin/includes/revision.php: wp_get_revision_ui_diff()
  • wp-admin/includes/meta-boxes.php: post_trackback_meta_box()
  • wp-admin/includes/meta-boxes.php: page_attributes_meta_box()
  • wp-admin/includes/meta-boxes.php: post_submit_meta_box()
  • wp-admin/includes/meta-boxes.php: post_format_meta_box()
  • wp-admin/includes/bookmark.php: edit_link()
  • wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::column_author()
  • wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::column_response()
  • wp-admin/includes/class-walker-nav-menu-edit.php: Walker_Nav_Menu_Edit::start_el()
  • wp-admin/includes/class-walker-nav-menu-checklist.php: Walker_Nav_Menu_Checklist::start_el()
  • wp-admin/includes/file.php: request_filesystem_credentials()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::inline_edit()
  • wp-admin/includes/widgets.php: wp_list_widget_controls()
  • wp-admin/includes/widgets.php: wp_widget_control()
  • wp-admin/includes/credits.php: _wp_credits_add_profile_link()
  • wp-admin/includes/credits.php: _wp_credits_build_object_link()
  • wp-admin/custom-header.php: Custom_Image_Header::step_1()
  • wp-includes/category-template.php: wp_generate_tag_cloud()
  • wp-includes/l10n.php: esc_html__()
  • wp-includes/l10n.php: esc_html_e()
  • wp-includes/l10n.php: esc_html_x()
  • wp-includes/formatting.php: sanitize_option()
  • wp-includes/formatting.php: wp_pre_kses_less_than_callback()
  • wp-includes/general-template.php: wp_login_form()
  • wp-includes/deprecated.php: wp_specialchars()
  • wp-includes/deprecated.php: the_content_rss()
  • wp-includes/class-wp-theme.php: WP_Theme::markup_header()
  • wp-includes/class-wp-theme.php: WP_Theme::__construct()
  • wp-includes/functions.php: wp_timezone_choice()
  • wp-includes/functions.php: wp_nonce_url()
  • wp-includes/functions.php: wp_upload_dir()
  • wp-includes/widgets/class-wp-nav-menu-widget.php: WP_Nav_Menu_Widget::form()
  • wp-includes/widgets/class-wp-widget-rss.php: WP_Widget_RSS::widget()
  • wp-includes/widgets.php: wp_widget_rss_output()
  • wp-includes/class-wp-embed.php: WP_Embed::maybe_make_link()
  • wp-includes/taxonomy.php: sanitize_term_field()
  • wp-includes/update.php: wp_version_check()
  • wp-includes/class-oembed.php: WP_oEmbed::data2html()
  • wp-includes/admin-bar.php: wp_admin_bar_site_menu()
  • wp-includes/option.php: wp_protect_special_option()
  • wp-includes/user.php: wp_dropdown_users()
  • wp-includes/user.php: sanitize_user_field()
  • wp-includes/class-walker-page-dropdown.php: Walker_PageDropdown::start_el()
  • wp-includes/post-template.php: wp_get_attachment_link()
  • wp-includes/media.php: wp_video_shortcode()
  • wp-includes/media.php: wp_audio_shortcode()
  • 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()
  • wp-includes/bookmark.php: sanitize_bookmark_field()
  • wp-includes/ms-deprecated.php: wpmu_admin_do_redirect()
  • wp-includes/nav-menu.php: wp_update_nav_menu_object()
  • wp-includes/rss.php: wp_rss()
  • wp-includes/rss.php: get_rss()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::pingback_ping()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getCategories()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getTags()
  • wp-includes/class-wp-customize-control.php: WP_Customize_Control::render_content()
  • wp-includes/widgets.php: wp_widget_description()
  • wp-includes/widgets.php: wp_sidebar_description()
  • wp-includes/comment-template.php: get_cancel_comment_reply_link()
  • wp-includes/comment-template.php: get_comment_author_email_link()
  • wp-includes/comment-template.php: comment_author_IP()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::output_widget_control_templates()
  • wp-includes/class-wp-editor.php: _WP_Editors::wp_link_query()
  • wp-includes/media-template.php: wp_print_media_templates()
  • Show 134 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 2You must log in to vote on the helpfulness of this note Contributed by Codex

    Examples

    
    $html = esc_html( '<a href="http://www.example.com/">A link</a>' );
    

    $html now contains this:

    
    <a href="http://www.example.com/">A link</a>
    

    which would be displayed in an HTML document as:

    <a href="http://www.example.com/">A link</a>

    Instead of like this:

    A link

  2. After using esc_html() on your example string you would have:

    <a href="http://www.example.com/">A link</a>

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

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

发布评论

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