ThinkPHP空格模糊查找

/**
     * @param $keywords string
     * @param $field string
     * @return array|string
     */
    public function advance_where_or($field,$keywords)
    {
        $keywords = trim($keywords);
        $keywords = preg_replace('/\s+/', ' ', $keywords);
        $where = [];
        if (strlen($keywords) > 0) {
            $keywordsArr = explode(" ", $keywords);
            if (count($keywordsArr) > 0) {
                $sql = "";
                $arrLen = count($keywordsArr);
                foreach ($keywordsArr as $k => $v) {
                    if ($k < $arrLen - 1) {
                        $sql .= " `" . $field . "` LIKE '%" . $v . "%' OR ";
                    }else{
                        $sql .= " `" . $field . "` LIKE '%" . $v . "%'";
                    }
                }
                $where = $sql;
            }
        }
        return $where;
    }

User::where(advance_where_or("nickname","张三 李四"))->select();

 

上一篇:虚拟机挂载共享文件的问题


下一篇:linux 虚拟机(Ubuntu)查看本地文件,设置共享文件夹