Home  >  Article  >  Backend Development  >  php like 查询

php like 查询

WBOY
WBOYOriginal
2016-06-23 13:32:351838browse

$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 '不存在';}

strpos楼上正解

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



$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 '不存在';}



谢谢 使用 $citys =$citya.$cityb; 就相加了
Statement:
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