1.使用php函数trim():
2.使用php函数 :str_replace():
3.使用php函数:strtr():
4.使用自己写的封装函数:
5.使用该正则去掉普通空格:
6.使用该正则去掉所有空格包括全角空格:
trim($str)
可去除字符串两侧的普通空格;2.使用php函数 :str_replace():
str_replace(' ','',$str)
3.使用php函数:strtr():
strtr($str,array(' '=>''))
4.使用自己写的封装函数:
function trimall($str)//删除空格
{
$limit=array(" "," ","\t","\n","\r");
$rep=array("","","","","");
return str_replace($limit,$rep,$str);
}
5.使用该正则去掉普通空格:
preg_replace('# #', '', $str)
6.使用该正则去掉所有空格包括全角空格:
$str =preg_replace("/\s| /","",$str);