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

来自:互联网
时间:2021-03-24
阅读:

方法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!
返回顶部
顶部