Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php strstr 函数判断字符串否存在

php strstr 函数判断字符串否存在

发布时间:2016-10-27   编辑:www.jquerycn.cn
jquery中文网为您提供php strstr 函数判断字符串否存在等资源,欢迎您收藏本站,我们将为您提供最新的php strstr 函数判断字符串否存在资源

$city_str=fopen(cgi_path."/data/weather/city.dat","r");
$city_ch=fread($city_str,filesize(cgi_path."/data/weather/city.dat"));
$city_ch_arr=explode("|",$city_ch);
//如果能匹配到所在市
if(strstr($area_ga,"市")){
foreach($city_ch_arr as $city_ch_arr_item){
  if(@strstr($area_ga,$city_ch_arr_item)){
   echo $area_ga.'<br>';
   echo $city_ch_arr_item;
   $s_city=$city_ch_arr_item;
  }
}
}//如果找不到市 那么看看是不是能找到省 有时会有这样的情况:广东省长城宽带 这样的一律归属到该省省府
elseif(strstr($area_ga,"河北")!==false){
$s_city="石家庄";
}elseif(strstr($area_ga,"福建")!==false){
$s_city="福州";
}elseif(strstr($area_ga,"台湾")!==false){
$s_city="台北";
}elseif(strstr($area_ga,"香港")!==false){
$s_city="香港";
}elseif(strstr($area_ga,"广西")!==false){
$s_city="南宁";
}elseif(strstr($area_ga,"浙江")!==false){
$s_city="杭州";
}elseif(strstr($area_ga,"江苏")!==false){
$s_city="南京";
}elseif(strstr($area_ga,"山东")!==false){
$s_city="济南";
}elseif(strstr($area_ga,"安徽")!==false){
$s_city="合肥";
}elseif(strstr($area_ga,"湖南")!==false){
$s_city="长沙";
}elseif(strstr($area_ga,"四川")!==false){
$s_city="成都";
}elseif(strstr($area_ga,"云南")!==false){
$s_city="昆明";
}elseif(strstr($area_ga,"广东")!==false){
$s_city="广州";
}elseif(strstr($area_ga,"贵州")!==false){
$s_city="贵阳";
}elseif(strstr($area_ga,"西藏")!==false){
$s_city="拉萨";
}elseif(strstr($area_ga,"新疆")!==false){
$s_city="乌鲁木齐";
}elseif(strstr($area_ga,"蒙古")!==false){
$s_city="呼和浩特";
}elseif(strstr($area_ga,"黑龙江")!==false){
$s_city="哈尔滨";
}elseif(strstr($area_ga,"辽宁")!==false){
$s_city="沈阳";
}elseif(strstr($area_ga,"吉林")!==false){
$s_city="长春";
}elseif(strstr($area_ga,"河南")!==false){
$s_city="郑州";
}elseif(strstr($area_ga,"湖北")!==false){
$s_city="武汉";
}elseif(strstr($area_ga,"山西")!==false){
$s_city="太原";
}elseif(strstr($area_ga,"陕西")!==false){
$s_city="西安";
}elseif(strstr($area_ga,"甘肃")!==false){
$s_city="兰州";
}elseif(strstr($area_ga,"宁夏")!==false){
$s_city="银川";
}elseif(strstr($area_ga,"海南")!==false){
$s_city="海口";
}elseif(strstr($area_ga,"江西")!==false){
$s_city="南昌";
}elseif(strstr($area_ga,"澳门")!==false){
$s_city="澳门";
}
//如果都不存在 就是默认显示广州 比如本地机
else{
$s_city="广州";
}

如上代码:
其中 city.dat中是一些城市 格式是这样的
广州|深圳|汕头|惠州|珠海|揭阳|佛山|河源|阳江|茂名|湛江|梅州|肇庆|韶关|潮州|东莞|中山|清远|江门|汕尾|云浮|增城|从化|乐昌|南雄|台山|开平|鹤山|恩平|廉江|雷州|吴川|高州|化州|高要|四会|兴宁|陆丰|阳春|英德|连州|普宁|罗定|北京|天津|上海|重庆|乌鲁木齐|克拉玛依|石河子|阿拉尔|图木舒克|五家渠|哈密|吐鲁番|阿克苏|喀什|和田|伊宁|塔城|阿勒泰|奎屯|博乐|昌吉|阜康|库尔勒|阿图什|乌苏|拉萨|日喀则|银川|石嘴山|吴忠|固原|中卫|呼和浩特|包头|乌海|赤峰|通辽|鄂尔多斯|呼伦贝尔|巴彦淖尔|乌兰察布|霍林郭勒|满洲里|牙克石|扎兰屯|根河|额尔古纳|丰镇|锡林浩特|二连浩特|乌兰浩特|


参考

echo strstr('aaaaaaaaaaaboaaaaaaaaaaaaboxcccccccccbcccccccccccccc','box')."n"; 

05 // 完整匹配中间的box 不因前而的b而停止 

06 echo strstr('aaaaaaAbaaa aaaa aaaaaaaaaboxccccccccccccboxccccccccccc','box')."n"; 

07 // 有两个关键字时, 遇到第一个停止. 

08 echo strstr('Subscrtibe our to free newsletter about New Freew to','to')."n"; 

09   
吧。

您可能感兴趣的文章:
php strstr查找字符串中是否包含某些字符
php strstr 函数判断字符串否存在
查找字符串中是否包含某些字符的函数strstr及其它
php判断是否包含字符
php判断字符与字符串的包含方法属性
php 保存网络图片,自动采集保存远程图片与文件
php strstr、stristr、strpos函数比较
php判断字符串是否含有指定字符串
php检测字符串是否包含字符串
php判断字符串是否包含另一个字符串例子

[关闭]