去除所有的空格 php

1、去除两边的空格   

  $arr=" shhs ";

  trim($arr)

2、正则匹配去除所有的空格   

 $goodid =“    ceshi    ”;

 $res=preg_replace('# #','',$goodid)

 print_r($res);

结果:

ceshi

第2种方案比较好,第一个trim 只能去掉左右的空格,但是不能去掉所有的,方案2,能去掉所以的空格;

猜你喜欢

转载自blog.csdn.net/qq_34861341/article/details/86159769
今日推荐