Home > php教程 > php手册 > body text

php通过数组实现多条件查询实现方法(字符串分割)

WBOY
Release: 2016-06-06 20:22:58
Original
1278 people have browsed it

这篇文章主要介绍了php通过数组实现多条件查询实现方法(字符串分割),需要的朋友可以参考下

复制代码 代码如下:


$keyword="asp php,jsp";
$keyword=str_replace(" "," ",$keyword);
$keyword=str_replace(" ",",",$keyword);
$keyarr=explode(',',$keyword);
for($index=0;$index{
$whereSql .= " And (arc.title like '%$keyarr[$index]%' Or arc.keywords like '%$keyarr[$index]%') ";
}
echo $whereSql;



为了同时支持空格与逗号,需要提前替换为统一的逗号,,就是先将空格都替换为逗号,然后再通过逗号分割字符串,然后循环拼接sql查询语句。

str_replace就是php中常用的字符串替换函数。
explode就是php中常用的字符串分割为数组的函数。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template