php删除字符串中的所有空格 ,其实是对trim函数的扩展 ,trim只能删除字符串两边的空格
代码如下:
function trimall($str)//删除空格 { $oldchar=array(" "," ","\t","\n","\r"); $newchar=array("","","","",""); return str_replace($oldchar,$newchar,$str); }
测试:
$str = " a b c d e f "; echo trimall($str);
输出结果:
abcdef