php刪除字符串中空格的方法:1、使用str_ireplace()函數(shù),語法“str_ireplace(' ', '', $str)”;2、使用str_replace()函數(shù),語法“str_replace(' ', '', $str)”。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦
方法1:使用str_ireplace()函數(shù)
<?php $str = 'hello world !'; $search = ' '; $replace = ''; echo str_ireplace($search, $replace, $str); ?>
輸出:
helloworld!
方法2:使用str_replace()函數(shù)
<?php $str = 'hello world !'; $str = str_replace(' ', '', $str); echo $str; ?>
輸出:
helloworld!
推薦學(xué)習(xí):《PHP視頻教程》