Home >Backend Development >PHP Tutorial >php 将字符串中的连续多个空格转换为一个空格

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

WBOY
WBOYOriginal
2016-06-20 13:04:012207browse

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

<p>/**</p>* 多个连续空格只保留一个<br />*<br />* @param string $string 待转换的字符串<br />* @return string $string 转换后的字符串<br />*/<br />function merge_spaces($string){<br />	return preg_replace("/\s(?=\s)/","\\1",$string);<br />}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn