php like 查询

WBOY
Release: 2016-06-23 13:32:35
Original
1813 people have browsed it

$SA_IP=北京市;

$citya =北京市,天津市;
$cityb =上海市,深圳市;
$citys =$citya+$cityb;

if($SA_IP==$citys){// 表示找到匹 ?>
       
    
  else{
  ?>
  
  }?>

就是当$SA_IP=北京市;,条件真。当$SA_IP=天津市;,条件真。 当$SA_IP=深圳市; ,条件真。

SQL有个like %% 可以模糊查询,就是我现在用PHP要怎么样去实现。


回复讨论(解决方案)

strpos

header ( 'Content-Type:text/html;charset=utf-8' );$SA_IP = '北京市';$citys = '北京市,天津市,上海市,深圳市';if (strpos ( $citys, $SA_IP ) !== false) {	echo '存在';} else {	echo '不存在';}
Copy after login
Copy after login
Copy after login

strpos楼上正解

header ( 'Content-Type:text/html;charset=utf-8' );$SA_IP = '北京市';$citys = '北京市,天津市,上海市,深圳市';if (strpos ( $citys, $SA_IP ) !== false) {	echo '存在';} else {	echo '不存在';}
Copy after login
Copy after login
Copy after login



$citya =北京市,天津市;
$cityb =上海市,深圳市;
$citys =$citya+$cityb;
$citys的数据是这$citya $cityb 相加的数据,能相加吗

header ( 'Content-Type:text/html;charset=utf-8' );$SA_IP = '北京市';$citys = '北京市,天津市,上海市,深圳市';if (strpos ( $citys, $SA_IP ) !== false) {	echo '存在';} else {	echo '不存在';}
Copy after login
Copy after login
Copy after login



谢谢 使用 $citys =$citya.$cityb; 就相加了
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!