5ucms论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 12921|回复: 0
打印 上一主题 下一主题

[钩子/函数] wp_strip_all_tags() 去除html标签

[复制链接]

670

主题

785

帖子

8253

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8253
跳转到指定楼层
楼主
发表于 2021-5-29 17:08:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. wp_strip_all_tags( string $string,  bool $remove_breaks = false )
复制代码

Properly strip all HTML tags including script and style

描述
This differs from strip_tags() because it removes the contents of the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' ) will return ‘something’. wp_strip_all_tags will return ”

参数
$string
(string)
(Required)
String containing HTML tags

$remove_breaks
(bool)
(Optional)
Whether to remove left over line breaks and white space chars

Default value: false

返回值
(string) The processed string.

源代码
File: wp-includes/formatting.php

function wp_strip_all_tags($string, $remove_breaks = false) {
        $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
        $string = strip_tags($string);

        if ( $remove_breaks )
                $string = preg_replace('/[\r\n\t ]+/', ' ', $string);

        return trim( $string );
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|5ucms.com

GMT+8, 2024-5-13 05:48 , Processed in 0.093750 second(s), 30 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表