php微信公众号开发之自动回复功能数据库建表及代码实例-勤勤学长

mysql数据库


关键词区分是用字母的 | 符号

php代码

所需要实现的功能:判断用户发来的文字信息中是否包含关键字

				$needle = '你们公司地址在哪呀';
				$data = db('zdhf')->select();
				foreach($data as $v1){
									
					$rule_name=$v1['rule_name'];
					$content = $v1['content'];		
						if(strstr($rule_name, '|')!== false){//|是用来区分的
							$content_array = explode("|",$rule_name);//用|把字符串分割成数组
							foreach($content_array as $v2){
								if(strstr($needle, $v2)!== false){
									return $content;
								}

							}
						}else{			
							if(strstr($needle,$rule_name)!== false){
									return $content;
							}
							
						}
					
					$content ='';	//能执行到这里就说明没有找到用户发来的信息中包含的关键字,如果找到的话在上边的时候已经跳出循环了				
				}	

猜你喜欢

转载自blog.csdn.net/qq318692996/article/details/79934962
今日推荐