5ucms论坛

标题: wp_strip_all_tags() 去除html标签 [打印本页]

作者: admin    时间: 2021-5-29 17:08
标题: wp_strip_all_tags() 去除html标签
  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 );
}




欢迎光临 5ucms论坛 (http://bbs.5ucms.com/) Powered by Discuz! X3.2