正确删除所有HTML标记,包括脚本和样式
原型
wp_strip_all_tags( string $string, bool $remove_breaks = false )
描述
这与strip_tags()不同,因为它删除了和标记的内容。例如。 strip_tags(‘ something </ script>’)将返回’something’。 wp_strip_all_tags将返回“
参数
$string
(string)
(Required)
包含HTML标记的字符串
$remove_breaks
(bool)
(Optional)
是否删除左侧断线和白色空间字符
返回值
(string)
已处理的字符串。
源文件
路径:wp-includes/formatting.php
<?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('/[rnt ]+/', ' ', $string);
return trim( $string );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_strip_all_tags/