/**
* Fetion notification weather forecast
* 2009-4-23
*/
//Disable execution time limit
set_time_limit (0);
//Set MB Encoding
mb_internal_encoding("GB2312");
/**
* Collect Sina weather forecast information
*
* @param string $city City name
* @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 "";
}
//Intercept relevant information
$return = "";
$star=strpos ($wf,"
");
$return = substr($wf,$star,1000);
$end2=strpos($return,"< ;!-- box end-->");
$return = strip_tags(substr($return,0,$end2));
//Filter
$return = str_replace(" ","",$return);
$return = str_replace(" ","",$return);
$return = str_replace("t","",$return);
$return = str_replace("n","",$return);
$return = str_replace("℃","degree",$return);
$return = str_replace("≤" ,"",$return);
$return = trim(str_replace("r",",",$return),",");
$return = str_replace("~","-" ,$return);
$return = str_replace(":",":",$return);
//Return value
return $return;
}
//Fetion account settings
$Fetion['user']='';
$Fetion['pass']='';
//Set weather forecast city
$citys[]=array('id'=>'bj','name'=>'Beijing');
$citys[]=array('id'=>'sy','name '=>'Shenyang');
//Beijing mobile phone number
$tel['bj'][]='137XXXXXXX';
$tel['bj'][]= '137XXXXXXX';
//Shenyang mobile phone number
$tel['sy'][]='138XXXXXXXX';
$tel['sy'][]='137XXXXXXX';
if (is_array($citys)&&count($citys)>0){
//Traverse cities
foreach($citys as $city){
//Get the collection information
$info=getWF($city['name']);
if (!empty($info)){
if (is_array($tel[$city ['id']])&&count($tel[$city['id']])>0){
171){
$starj=168 *$i;
$qInfo=mb_substr($info,$starj,168); foreach($tel[$city['id']] as $ val){
$url="http://sms.api.bz/fetion.php?username=".$Fetion['user']."&password=".$Fetion['pass']." &sendto=".$val."&message=".urlencode("Weather forecast[".$n."],"."Tomorrow".date("Y year m month d day")." ".$city[ 'name']." ".$qInfo);
$url="http://sms.api.bz/fetion. php?username=".$Fetion['user']."&password=".$Fetion['pass']."&sendto=".$val."&message=".urlencode("Weather forecast, tomorrow".date ("M, d, Year Y")." ".$city['name']." ".$info); 🎜> }
As follows:
//Fetion account settings
$Fetion['user']='Your own Fetion account mobile number';
$Fetion['pass']='Log in to Fetion Password';
Change your city
Copy code
The code is as follows:
/ /Set weather forecast cities$citys[]=array('id'=>'bj','name'=>'Beijing');
Modify what you want to receive The weather forecast mobile phone number can be multiple
Copy code
The code is as follows:
//Beijing mobile phone number$ tel['bj'][]='137XXXXXXX'; $tel['bj'][]='137XXXXXXX';
The bj here should be the same as the bj in the set city
Now that the configuration is complete, you can test whether you can receive weather forecast information.
4. Set daily scheduled sending
If it is a WINDOWS environment, set up scheduled tasks
Start->Programs->Nearby->System Tools->Scheduled Tasks
Add tasks and follow the prompts The key point is to select PHP.exe to execute the program
Select the location where you installed APMServ. My local one is D:APMServ5.2.6PHPphp.exe. The absolute path to WeatherForecast.php
My local one is D:APMServ5.2.6PHPphp.exe D: APMServ5.2.6wwwhtdocsWeatherForecast.php Done.
http://www.bkjia.com/PHPjc/320140.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/320140.html
TechArticle
Let’s start by teaching you how to do it. 1. You need a PHP environment. In order to save trouble, download the APMServ software to quickly build a PHP environment. 2. Download the weather forecast SMS notification PHP program. Click here to download the code. 3....