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

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

WBOY
Release: 2016-06-20 13:04:01
Original
2179 people have browsed it

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 />}
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template