php怎么删除字符串中的空格

方法1:使用str_ireplace()函数

<?php
$str = 'hello world !';
$search = ' ';
$replace = '';
echo str_ireplace($search, $replace, $str);
?>

输出:

helloworld!

方法2:使用str_replace()函数

<?php
$str = 'hello world !';
$str = str_replace(' ', '', $str);
echo $str;
?>

输出:

helloworld!
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容