PHP combined fetion free weather message _php instance

Source: Internet
Author: User
Tags urlencode
Start teaching you how to do it.
One, need to have a PHP environment. Download Apmserv software to quickly build PHP environment
Second, download the Weather Report SMS notification PHP program point here to download code
Third, modify the PHP program configuration
Open weatherforecast.php file with Notepad
Copy CodeThe code is as follows:
/**
* FETION Notification Weather forecast
* 2009-4-23
*/

Prohibit 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 related information
$return = "";
$star =strpos ($WF, "");
$return = substr ($WF, $star, 1000);
$end 2=strpos ($return, " ");
$return = Strip_tags (substr ($return, 0, $end 2));


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 the city
foreach ($citys as $city) {

Get acquisition information
$info =GETWF ($city [' name ']);

if (!empty ($info)) {
if (Is_array ($tel [$city [' ID ']]) &&count ($tel [$city [' ID ']] >0) {

Large amount of information processing
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 year M D Day ")." ". $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 year M D Day ")." ". $city [' name ']." ". $info);
@file_get_contents ($url);
}
}
}
}
}
}
?>

Modify
Copy CodeThe code is as follows:
Fetion Account Settings
$Fetion [' User ']= ' own fetion account phone number ';
$Fetion [' Pass ']= ' login fetion password ';

Changes in your city
Copy CodeThe code is as follows:
Set weather Forecast City
$citys []=array (' id ' = ' bj ', ' name ' = ' Beijing ');

Modify the phone number you want to receive the weather forecast for multiple
Copy CodeThe code is as follows:
Beijing Mobile Phone Number
$tel [' BJ '][]= ' 137XXXXXXX ';
$tel [' BJ '][]= ' 137XXXXXXX ';

BJ here is going to be the same as BJ in setting up the city
Okay, OK. The configuration is complete to test whether you can receive the weather forecast information.
Four, set the daily scheduled send
If the Windows environment Settings scheduled task
Scheduled tasks, near the start, next to Programs, System Tools
Add task based on prompt action focus on executing program selection PHP.exe
Select the seat where you installed Apmserv my local is D:\APMServ5.2.6\PHP\php.exe weatherforecast.php absolute path
I'm local to D:\APMServ5.2.6\PHP\php.exe D:\APMServ5.2.6\www\htdocs\WeatherForecast.php.
Complete.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.