php去除所有空格的方法
首先创建一个PHP示例文件;然后通过"trim($str);"
方法去掉头尾空格;最后通过"preg_replace"
表达式去除所有空格即可。
$str = " This line contains\tliberal \r\n use of whitespace.\n\n";
$str = trim($str);// 首先去掉头尾空格
$str = preg_replace('/\s(?=\s)/', ‘’, $str);// 接着去掉两个空格以上的
$str = preg_replace(’/[\n\r\t]/’, ‘ ‘, $str);//