首页 > 开发 > PHP > 正文

php结合飞信 免费天气预报短信

2024-05-04 22:11:22
字体:
来源:转载
供稿:网友
开始教你怎么弄
一、需要有一个PHP环境。为了图省事下载APMServ软件快速搭建PHP环境
二、下载天气预报短信通知PHP程序点这里下载代码
三、修改PHP程序配置
用记事本打开WeatherForecast.php文件
代码如下:
<?
/**
* 飞信通知天气预报
* 2009-4-23
*/

//禁止执行时间限制
set_time_limit (0);

//设置MB编码
mb_internal_encoding("GB2312");

/**
* 采集新浪天气预报信息
*
* @param string $city    城市名称
* @return unknown
*/
function getWF($city){

    if(empty($city)) return "";
    $wf=@file_get_contents('http://php.weather.sina.com.cn/search.php?city='.urlencode($city).'&f=1&dpc=1');
    if (empty($wf)){
        return "";
    }

    //截取相关信息
    $return = "";
    $star=strpos($wf,"<div class=/"blk-s3/">");
    $return = substr($wf,$star,1000);
    $end2=strpos($return,"<!-- box end-->");
    $return = strip_tags(substr($return,0,$end2));

    
    //过滤
    $return = str_replace(" ","",$return);
    $return = str_replace(" ","",$return);
    $return = str_replace("/t","",$return);
    $return = str_replace("/n","",$return);
    $return = str_replace("℃","度",$return);
    $return = str_replace("≤","",$return);
    $return = trim(str_replace("/r",",",$return),",");
    $return = str_replace("~","-",$return);
    $return = str_replace(":",":",$return);

    //返回值
    return $return;
}

//飞信账号设置
$Fetion['user']='';
$Fetion['pass']='';

//设置天气预报城市
$citys[]=array('id'=>'bj','name'=>'北京');
$citys[]=array('id'=>'sy','name'=>'沈阳');

//北京手机号
$tel['bj'][]='137XXXXXXX';
$tel['bj'][]='137XXXXXXX';
//沈阳手机号
$tel['sy'][]='138XXXXXXXX';
$tel['sy'][]='137XXXXXXX';


if (is_array($citys)&&count($citys)>0){

    //遍历城市
    foreach($citys as $city){

        //获取采集信息
        $info=getWF($city['name']);

        if (!empty($info)){
            if (is_array($tel[$city['id']])&&count($tel[$city['id']])>0){
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表