normalize_whitespace

函数
normalize_whitespace ( $str )
参数
  • (string) $str The string to normalize.
    Required:
返回值
  • (string) The normalized string.
定义位置
相关方法
wp_normalize_site_datawp_normalize_pathwp_kses_normalize_entities_split_str_by_whitespace_prime_site_caches
引入
2.7.0
弃用
-

normalize_whitespace: 这个函数在一个给定的字符串中用一个空格字符替换了多个连续的空白字符。它通常用于规范用户输入或其他可能包含不一致的空白的字符串。

规范化的EOL字符和剥离重复的空白。

function normalize_whitespace( $str ) {
	$str = trim( $str );
	$str = str_replace( "r", "n", $str );
	$str = preg_replace( array( '/n+/', '/[ t]+/' ), array( "n", ' ' ), $str );
	return $str;
}

常见问题

FAQs
查看更多 >