Home > Backend Development > PHP Tutorial > Free weather forecast SMS php combined with Fetion Free weather forecast SMS

Free weather forecast SMS php combined with Fetion Free weather forecast SMS

WBOY
Release: 2016-07-29 08:39:51
Original
1137 people have browsed it

Let’s start 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. Modify the PHP program configuration. Open the WeatherForecast.php file with Notepad.



Copy the code.

The code is as follows :


/**
* 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 "";
$star= strpos($wf,"

");
$return = substr($wf,$star,1000);
$end2=strpos($return,"");
$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 cities
$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( { 'id']])&&count($tel[$city['id']])>0){
                                                                                                                                                            ​ceil (mb_strlen($info)/168)-1;
                                                                                               $qInfo=mb_substr($info,$ starj,168);
                                                                                         $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);
                                                             
                                                                                                                                                                                                                                                                                                     tion[' user']."&password=".$Fetion['pass']."&sendto=".$val."&message=".urlencode("Weather forecast, tomorrow".date("Y year m month d day") ." ".$city['name']." ".$info);
                                                                                                                                                                                     
Copy the code

The code is as follows:


//Fetion account settings
$Fetion['user']='your own Fetion account mobile phone number';
$Fetion['pass']='log in Fetion password';

Change your city

Copy the code The code is as follows:

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


Modify the mobile phone number you want to receive the weather forecast for. You can copy the code for multiple



. 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 city setting
After the configuration is completed, you can test and execute it to see if you can receive the weather Forecast information.
4. Set up daily scheduled sending

If it is a WINDOWS environment, set up scheduled tasksStart->Programs->Nearby->System Tools->Scheduled TasksAdd tasks Follow the prompts and focus on executing the program and select PHP.exe Choose the location where you installed APMServ. My local one is D:APMServ5.2.6PHPphp.exe WeatherForecast.php. My local one is D:APMServ5.2.6PHPphp.exe D:APMServ5.2.6wwwhtdocsWeatherForecast.php

Complete.

The above introduces the free weather forecast SMS using PHP combined with Fetion, including the content of free weather forecast SMS. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template