php删除字符串中空格的方法:1、使用str_ireplace()函数,语法“str_ireplace(' ', '', $str)”;2、使用str_replace()函数,语法“str_replace(' ', '', $str)”。
本教程操作环境:windows7系统、PHP7.1版,DELL G3电脑
方法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!推荐学习:《PHP视频教程》
以上就是php怎么删除字符串中的空格的详细内容!
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did52262
php怎么删除字符串中的空格
阅读:42次