PHP去除字符串中的空格

去除字符串到的空格有多种方法,下面介绍两种给大家:

使用 str_replace :

<?php
$string = str_replace(' ', '', $string);
?>

使用 preg_replace :

<?php
$string = preg_replace('/\s+/', '', $string);
?>

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据