php method to remove spaces in a string: first create a PHP sample file; then delete all spaces in the specified string through the "str_replace(' ', '', ' a bab ');" method Can.
Recommended: "PHP Video Tutorial"
Remove all spaces in the string
<?php //删除所有空格 echo str_replace(' ', '', ' a bab ');echo "\n"; echo preg_replace('/ /', '', ' ab ab ');echo "\n"; echo strtr(' ab ab ', array(' '=>''));echo "\n"; function trimall($str)//删除所有的空格 { $qian=array(" "," ","\t","\n","\r"); $hou=array("","","","",""); return str_replace($qian,$hou,$str); } echo trimall(" a v "); echo "\n"; ?>
The result is as shown:
The above is the detailed content of php remove spaces from string. For more information, please follow other related articles on the PHP Chinese website!