php去除数据库的数据空格

//遍历更新
foreach ($list as $key => $value) {
    $value['goodsname'] = $this->trimall($value['goodsname']);
    $value['measureunit'] = $this->trimall($value['measureunit']);
    $goodsLogic->saveByData($value,array('id'=>$value['id']));
}
/**
 * 说明:新增/修改
 * 作者: panzhide
 * 时间: 2020/8/14
 * @param string $where
 * @return string
 */
public static function saveByData($data, $where = [])
{
    $model = BaseModelFactory::create('Goods', 'stock');
    $res = $model->allowField(true)->save($data, $where);
    return $res;
}
//删除空格
public function trimall($str)
{
    $oldchar=array(" "," ","\t","\n","\r");
    $newchar=array("","","","","");
    return str_replace($oldchar,$newchar,$str);
}

 

posted @ 2020-11-17 11:46  潘潘潘的博客  阅读(216)  评论(0编辑  收藏  举报