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