Home  >  Article  >  Backend Development  >  How to replace multiple spaces in php

How to replace multiple spaces in php

藏色散人
藏色散人Original
2020-09-30 09:12:423853browse

php替换多个空格的方法:首先创建一个PHP示例文件;然后定义一个“merge_spaces”方法;最后通过正则表达式“preg_replace("/\s(?=\s)/","\\1",$string);”去除多个空格并保留一个即可。

How to replace multiple spaces in php

推荐:《PHP视频教程

php多空格只保留一个的方法

代码:

function merge_spaces($string){
return preg_replace("/\s(?=\s)/","\\1",$string);
}

The above is the detailed content of How to replace multiple spaces in php. For more information, please follow other related articles on the PHP Chinese website!

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