PHP combined with flying free weather forecast SMS _php Instance

Source: Internet
Author: User
Tags urlencode
Start teaching you how to get
One, need to have a PHP environment. To download Apmserv software to quickly build PHP environment
Second, download the weather Forecast SMS Notification PHP program point here Download code
Third, modify the PHP program configuration
Open weatherforecast.php file with Notepad
Copy Code code as follows:

?
/**
* Flying letter to inform the weather forecast
* 2009-4-23
*/

Prohibit execution time limit
Set_time_limit (0);

Set MB encoding
Mb_internal_encoding ("GB2312");

/**
* Collect information on Sina weather forecast
*
* @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 "";
}

Interception of relevant information
$return = "";
$star =strpos ($WF, "<div class=\" blk-s3\ ">");
$return = substr ($WF, $star, 1000);
$end 2=strpos ($return, "<!--box end-->");
$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;
}

Flying Letter Account Settings
$Fetion [' User ']= '];
$Fetion [' Pass ']= '];

Set up a 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) {

Traversing the city
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) {

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-month 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-month D-Day ")." ". $city [' name ']." ". $info);
@file_get_contents ($url);
}
}
}
}
}
}
?>

Modify
Copy Code code as follows:

Flying Letter Account Settings
$Fetion [' User ']= ' own flying letter account phone number ';
$Fetion [' Pass ']= ' login letter password ';

Changes in your city
Copy Code code as follows:

Set up a weather forecast city
$citys []=array (' id ' => ' bj ', ' name ' => ' Beijing ');

Change the number of phone numbers you want to receive the weather forecast for multiple
Copy Code code as follows:

Beijing Mobile Phone Number
$tel [' BJ '][]= ' 137XXXXXXX ';
$tel [' BJ '][]= ' 137XXXXXXX ';

BJ here is going to be the same as the Setup City BJ.
All right, configuration complete. You can test to see if you can receive weather information.
Four, set the daily scheduled send
If the Windows environment set up a scheduled task
Start-> program-> near-> System Tools-> Scheduled Tasks
Add a task follow the prompts to focus on the execution program select PHP.exe
Choose the seat where you install Apmserv my local is D:\APMServ5.2.6\PHP\php.exe weatherforecast.php absolute path
My local for 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.