php 将字符串中的连续多个空格转换为一个空格

转载自:http://www.phpernote.com/php-function/633.html

/**

* 多个连续空格只保留一个

*

* @param string $string 待转换的字符串

* @return string $string 转换后的字符串

*/

function merge_spaces($string){

	return preg_replace("/\s(?=\s)/","\\1",$string);

}

 

你可能感兴趣的:(PHP)