php去除数据库的数据空格

时间:2020-11-17 15:59:43   收藏:0   阅读:37
//遍历更新
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);
}

 

原文:https://www.cnblogs.com/seanpan/p/13993432.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!