仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1969|回复: 20
打印 上一主题 下一主题

[学习教程] PHP网页编程之PHP飞信告诉天色预告_API版

[复制链接]
萌萌妈妈 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:33:50 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
不懂的问题有很多高手帮你解决。但不要认为你是新手,就不能帮助别人,比如今天你学会了怎样安装PHP,明天还可能有朋友会问这个问题,你就可以给他解答,不要认为这是浪费时间,忙别人其实就是帮助自己。     
    PHP飞信告诉天色预告_API版
    假如前提答应可以在办事器上用企图义务 天天在固准时间给本人或亲人发送天色预告
    采取飞信官方web接口
    有时能够因为办事器速度成绩能够形成发送不胜利.属于正常景象.
   
    
    /***************************************************************************/
    /******************* PHP飞信告诉天色预告_API版 *******************************/
    /*************************** 2011-12-5 ************************************/
    /**************************作者:xiaogg*************************************/
    /***************************版本:2.11**************************************/
    /*********************http://www.bitefu.net********************************/
    header("content-Type: text/html; charset=utf-8");
    function curl_file_get_contents($durl){
    if(function_exists('curl_setopt')){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $durl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
    curl_setopt($ch, CURLOPT_REFERER,_REFERER_);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $r = curl_exec($ch);
    curl_close($ch);
    }else if(function_exists('file_get_contents')){
    $r=file_get_contents($durl);
    }else if(function_exists('file')){
    $r=file($durl);$r = implode('', $r);
    }else{
    $r="获得内容掉败";
    }
    return $r;
    }
    //删除空格
    function wtrimall($str,$type=0)
    {
    $str= str_replace(" ","*-*",$str);
    $str= str_replace(" ","*-*",$str);
    $str= str_replace("\t","*-*",$str);
    $str_s= str_replace("\n","*-*",$str);
    $str= str_replace("*-*","",$str_s);
    if($type==1)return $str_s;else return $str;
    }
    //对数组停止键值排序
    function wchangearray($str)
    {
    return array_values(array_filter($str));
    }
    function wtext($city,$weather_txt="weahter.txt")
    {
    $date=date("Y-m-d");$arr=array();$arr['date']=$date;
    if(!file_exists($weather_txt)){file_put_contents($weather_txt,serialize($arr));}
    $old=unserialize(file_get_contents($weather_txt));
    if($old['date']!=$date){file_put_contents($weather_txt,serialize($arr));}
    if($old[$city] && strlen($old[$city])>30){return $old[$city];}else{
    switch($city)
    {
    case "sjz": $url = 'http://www.weather.com.cn/weather/101090101.shtml';$text="石家庄";break;
    case "yt": $url = 'http://www.weather.com.cn/weather/101090508.shtml';$text="玉田";break;
    }
    $lines_string = curl_file_get_contents($url);
    $lines_string = explode("','',$lines_string[1]),str_replace('2-->','',$lines_string[2]),str_replace('3-->','',$lines_string_3[0]));
    for($i=0;$i< count($lines_array); $i ++)
    {
    $nowarray=strip_tags($lines_array[$i]);
    $datearray=explode("日",$nowarray);$nowdata=wtrimall($datearray[0]);//获得日期
    $weather=explode("日间",$nowarray);$weather=explode("夜间",$weather[1]);
    $weather_bai=wtrimall(str_replace("低温 ","",$weather[0]));$weather_bai=str_replace("℃","度",$weather_bai);//日间天色
    $weather_ye=wtrimall(str_replace("高温 ","",$weather[1]));$weather_ye=str_replace("℃","度",$weather_ye);//夜间天色
    $baiarr=wchangearray(explode("\r",$weather_bai));$yearr=wchangearray(explode("\r",$weather_ye));
    $wtext[$i]=trim($nowdata)."日";
    if($baiarr[0]==$yearr[0]){$wtext[$i].=$baiarr[0];}else{$wtext[$i].=$baiarr[0]."转".$yearr[0];}//将天色添加到前往值里
    $wtext[$i].=$baiarr[1]."到".$yearr[1];//将气温添加到前往值里
    if($baiarr[2]==$yearr[2]){$wtext[$i].=$baiarr[2];}else{$wtext[$i].=str_replace("风","",$baiarr[2]."转".$yearr[2]);$wtext[$i].="风";}//将风向添加到前往值里
    if($baiarr[3]!="和风"){$wtext[$i].=$baiarr[3];}//将风力添加到前往值里
    }
    $new=$text.implode("",$wtext);
    if(strlen($new)<30){$new=wtext($city);};
    $newarr=array($city=>$new);
    file_put_contents($weather_txt,serialize(array_unique(array_merge($old,$newarr))));
    return $new;
    }
    }
    //设置装备摆设入手下手
    $phone_num = "150******";//在这修正为您的手机号码;
    $password = "******" ;//在这修正为您的飞信暗码
    $phone="150******yt;134******yt;151******sjz;150******sjz";//在这修正为要发送的德律风号码,多个发送用,分隔。注:必需是您的飞信密友
    //设置装备摆设停止
    $tophone=explode(";",$phone);
    //发送短信
<p>   for($i=0;$i
萌萌妈妈 该用户已被删除
沙发
 楼主| 发表于 2015-3-8 22:05:57 | 显示全部楼层
php是动态网站开发的优秀语言,在学习的时候万万不能冒进。在系统的学习前,我认为不应该只是追求实现某种效果,因为即使你复制他人的代码调试成功,实现了你所期望的效果,你也不了解其中的原理。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-16 16:56

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表