PHP letter to inform the weather forecast _API version
If conditions allow you to use scheduled tasks on the server to send weather forecasts to yourself or your loved ones at a fixed time each day
Adopt the official web interface of flying letter
Sometimes a problem with server speed may result in an unsuccessful delivery. It's normal.
/***************************************************************************/
/******************* PHP letter to inform the weather forecast _api version *******************************/
/*************************** 2011-12-5 ************************************/
/************************** Author: xiaogg*************************************/
/*************************** version: 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 = "Get content failed";
}
return $r;
}
Remove spaces
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 the _s;else return $str;
}
Sorting array keys
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 = "Shijiazhuang";
Case "YT": $url = ' http://www.weather.com.cn/weather/101090508.shtml '; $text = "Yutian";
}
$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 ("Day", $nowarray); $nowdata =wtrimall ($datearray [0]); Get date
$weather =explode ("daytime", $nowarray); $weather =explode ("Night", $weather [1]);
$weather _bai=wtrimall (Str_replace ("High Temperature", "", $weather [0])); $weather _bai=str_replace ("℃", "degree", $weather _bai);/day weather
$weather _ye=wtrimall (Str_replace ("Low Temperature", "", $weather [1])); $weather _ye=str_replace ("℃", "degree", $weather _ye);/night Weather
$baiarr =wchangearray (Explode ("\ r", $weather _bai)); $yearr =wchangearray (Explode ("\ r", $weather _ye));
$wtext [$i]=trim ($nowdata). " Day ";
if ($baiarr [0]== $yearr [0]) {$wtext [$i].= $baiarr [0];} else{$wtext [$i].= $baiarr [0]. " Turn ". $yearr [0];} Add weather to return value
$wtext [$i].= $baiarr [1]. " to the. $yearr [1];//adds temperature to the return value
if ($baiarr [2]== $yearr [2]) {$wtext [$i].= $baiarr [2];} else{$wtext [$i].=str_replace ("Wind", "", $baiarr [2]. " Turn ". $yearr [2]); $wtext [$i].=" Wind ";} Add wind to return value
if ($baiarr [3]!= "Breeze") {$wtext [$i].= $baiarr [3];} Adding wind to the return value
}
$new = $text. Implode ("", $wtext);
if (strlen ($new) <30) {$new =wtext ($city);};
$newarr =array ($city => $new);
File_put_contents ($weather _txt,serialize (Array_merge ($old, $newarr)));
return $new;
}
}
Configuration start
$phone _num = "150******";//change in this for your mobile number;
$password = "Hu Jintao";//change in this code for your flying letter
$phone = "150******YT;134******YT;151******SJZ;150******SJZ";//change in this to the phone number to send, multiple send, separate. Note: Must be your flying friend
Configuration End
$tophone =explode (";", $phone);
Send SMS
for ($i =0; $i<>< p=""> <>
$sys =explode ("", $tophone [$i]);
$url = "http://www.bitefu.net/fetion/";
$url. = "phone=". $phone _num. " &pwd= ". $password." &to= ". $sys [0]." &u=1&msg= ". Wtext ($sys [1]);//&u=1 This parameter is sent in the content of garbled when added, if there is garbled problem can be removed from this parameter
File_get_contents ($url);
}if ($i ==count ($tophone)) {sleep (100);
?> <script></script>