How to replace multiple spaces in php

藏色散人
Release: 2023-03-06 10:24:02
Original
3866 people have browsed it

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

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!

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