ThinkPHP空格模糊查找
Posted 正焕
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
以上是关于ThinkPHP空格模糊查找的主要内容,如果未能解决你的问题,请参考以下文章