Start to teach you how to get it
1. a PHP environment is required. Download APMServ software to quickly build a PHP Environment
2. Download the weather forecast Text Message notification PHP program. Click here to download the code
3. Modify the PHP program Configuration
Use NotePad to open the WeatherForecast. php file
Copy codeThe Code is as follows:
<?
/**
* Apsara notification Weather Forecast
* 2009-4-23
*/
// Execution prohibition time limit
Set_time_limit (0 );
// Set the MB Encoding
Mb_internal_encoding ("GB2312 ");
/**
* Collect Sina weather forecast information
*
* @ Param string $ 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 related information
$ 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 ));
// 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;
}
// Set the Apsara stack account
$ Fetion ['user'] = '';
$ Fetion ['pass'] = '';
// Set the weather forecast City
$ Citys [] = array ('id' => 'bj ', 'name' => 'beijing ');
$ Citys [] = array ('id' => 'sys', 'name' => 'shenyang ');
// Beijing mobile phone number
$ Tel ['bj '] [] = '137xxxxxxx ';
$ Tel ['bj '] [] = '137xxxxxxx ';
// Shenyang mobile phone no.
$ Tel ['sy '] [] = '138xxxxxxxx ';
$ Tel ['sy '] [] = '137xxxxxxx ';
If (is_array ($ citys) & count ($ citys)> 0 ){
// Traverse the city
Foreach ($ citys as $ city ){
// Obtain the collection information
$ Info = getWF ($ city ['name']);
If (! Empty ($ info )){
If (is_array ($ tel [$ city ['id']) & count ($ tel [$ city ['id'])> 0 ){
// Process large amounts of information
If (mb_strlen ($ info)> 171 ){
$ Sum = ceil (mb_strlen ($ info)/168)-1;
For ($ I = 0; $ I <= $ sum; $ I ++ ){
$ Starj= 168 * $ I;
$ QInfo = mb_substr ($ info, $ starj, 168 );
$ N = $ I + 1;
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, m, D "). "". $ city ['name']. "". $ qInfo );
@ File_get_contents ($ url );
}
}
} Else {
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, tomorrow ". date ("Y, m, D "). "". $ city ['name']. "". $ info );
@ File_get_contents ($ url );
}
}
}
}
}
}
?>
Modify
Copy codeThe Code is as follows:
// Set the Apsara stack account
$ Fetion ['user'] = 'mobile phone number of your Apsara stack account ';
$ Fetion ['pass'] = 'login to Fetion password ';
Modify your city
Copy codeThe Code is as follows:
// Set the weather forecast City
$ Citys [] = array ('id' => 'bj ', 'name' => 'beijing ');
Modify the phone number for which you want to receive the weather forecast.
Copy codeThe Code is as follows:
// Beijing mobile phone number
$ Tel ['bj '] [] = '137xxxxxxx ';
$ Tel ['bj '] [] = '137xxxxxxx ';
Bj here must be the same as bj in the city.
After the configuration is complete, you can test whether the weather forecast information can be received.
4. Set daily scheduled sending
In WINDOWS, set the scheduled task
Start> program> nearby> System Tools> Schedule Tasks
Add a task as prompted. Click "php.exe" in the execution program.
Select the location where you want to install APMServ. My local location is D: \ APMServ5.2.6 \ PHP \ php.exe WeatherForecast. php absolute path.
I am local D: \ APMServ5.2.6 \ PHP \ php.exe D: \ APMServ5.2.6 \ www \ htdocs \ WeatherForecast. php
Complete.