wp_strip_all_tags

函数


wp_strip_all_tags ( $string, $remove_breaks = false )
参数
  • (string)
    $string
    String containing HTML tags
    Required:
  • (bool)
    $remove_breaks
    Optional. Whether to remove left over line breaks and white space chars
    Required:
    Default: false
返回值
  • (string) The processed string.
定义位置
  • wp-includes/formatting.php
    , line 5394
引入
2.9.0
弃用

Properly strips all HTML tags including script and style

This differs from strip_tags() because it removes the contents of
the “ and “ tags. E.g. `strip_tags( ‘something’ )`
will return ‘something’. wp_strip_all_tags will return ”

function wp_strip_all_tags( $string, $remove_breaks = false ) {
	$string = preg_replace( '@]*?>.*?1>@si', '', $string );
	$string = strip_tags( $string );

	if ( $remove_breaks ) {
		$string = preg_replace( '/[rnt ]+/', ' ', $string );
	}

	return trim( $string );
}