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_script_add_datawp_set_post_tagswp_scriptswp_get_script_tagwp_stream_image
引入
2.9.0
棄用
-

wp_strip_all_tags。它從一個字串中刪除所有的HTML標籤: 該函式從一個字串中刪除所有HTML標籤,只留下純文字內容。

正確地剝離所有HTML標籤,包括指令碼和樣式。

這與 strip_tags() 不同,因為它刪除了“和“標籤的內容。例如:`strip_tags( ‘something’)`將返回’something’。wp_strip_all_tags將返回” 。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >