Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
wp_strip_all_tags() - 正确剥离所有HTML标签,包括脚本和样式 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / wp_strip_all_tags()

wp_strip_all_tags( string $string, bool $remove_breaks = false )

正确剥离所有HTML标签,包括脚本和样式


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 4 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "8ca5ef5829f56b51f027f5db7a2a7433" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "1a8ced63f83b1206da7f2b42f6ccac39" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "a935db3d255e17450f4b387b9565b626" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

allmore...

tagmore...


描述

这与strip_tags()不同,因为它删除了<script>和<style>标签的内容。如:strip_tags( '<script>something</script>' )将返回“something”,wp_strip_all_tags将返回''


参数

$string

(string)(必填) 包含HTML标签的字符串

$remove_breaks

(bool)(可选) 是否删除剩余的换行符和空白字符

默认值: false


返回

(string) 处理后的字符串。


更多信息

默认情况下,wp_strip_all_tags()被添加到以下过滤器中(请参见wp-includes/default-filters.php):

  • pre_comment_author_url
  • pre_user_url
  • pre_link_url
  • pre_link_image
  • pre_link_rss
  • pre_post_guid

默认情况下,在站点的管理端,它也应用于这些过滤器:

  • user_url
  • link_url
  • link_image
  • link_rss
  • comment_url
  • post_guid


源码

查看源码 官方文档


更新日志

版本描述
2.9.0开始引入

使用示例

  • 示例1

    实例

    $html = '<strong>I am not strong</strong>';
    var_dump($html);
    //output '<strong>I am not strong</strong>'
    
    var_dump(wp_strip_all_tags($html));
    //output 'I am not strong'