


PHP collected weather forecast code examples covering the entire country from the Central Meteorological Observatory, Central Meteorological Observatory Weather Forecast_PHP Tutorial
php collected weather forecast code examples from the Central Meteorological Observatory covering the whole country, Central Meteorological Observatory weather forecast
The example in this article describes the weather forecast code collected by PHP from the Central Meteorological Observatory covering the whole country. Share it with everyone for your reference. The specific analysis is as follows:
Weather forecast information is collected from the Central Meteorological Observatory. The information is accurate, wide coverage, and the code is simple. The return is json code, which can be used for client calls or displayed after processing on the server side. The author's WordPress weather forecast plug-in is used Please note that this code will generate a cache file on the server. You need to create a new data folder in the current directory to ensure that the folder is writable.
php weather forecast code is as follows:
Author: freemouse
Home page: www.cnphp.info
Interface demo: http://www.cnphp.info/tianqi
Usage: You can directly call the above address to display local weather information, or you can use it like this
http://www.cnphp.info/tianqi/?q=Nanjing, Jiangsu Province
**/
$p = $_get['q'];
$k = 0;
$encoding = mb_detect_encoding($p);
if($encoding != "utf-8"){
$p = mb_convert_encoding($p,"utf-8","gbk");
}
$p_arr = array(
"01" => "Beijing",
"02" => "Shanghai",
"03" => "Tianjin",
"04" => "Chongqing",
"05" => "Heilongjiang",
"06" => "Jilin",
"07" => "Liaoning",
"08" => "Inner Mongolia",
"09" => "Hebei",
"10" => "Shanxi",
"11" => "Shaanxi",
"12" => "Shandong",
"13" => "Xinjiang",
"14" => "Tibet",
"15" => "Qinghai",
"16" => "Gansu",
"17" => "Ningxia",
"18" => "Henan",
"19" => "Jiangsu",
"20" => "Hubei",
"21" => "Zhejiang",
"22" => "Anhui",
"23" => "Fujian",
"24" => "Jiangxi",
"25" => "Hunan",
"26" => "Guizhou",
"27" => "Sichuan",
"28" => "Guangdong",
"29" => "Yunnan",
"30" => "Guangxi",
"31" => "Hainan",
"32" => "Hong Kong",
"33" => "Macau",
"34" => "Taiwan"
);
function find(&$item,$key,$data){
global $k;
If(preg_match("/$item/u",$data)){
$k = $key;
}
If(!file_exists("./data/city{$key}.xml")){
$c =file_get_contents( "http://m.weather.com.cn/data5/city{$key}.xml" );
file_put_contents("./data/city{$key}.xml",$c);
else{
$c = file_get_contents("./data/city{$key}.xml");
$arr = explode(",",$c);
foreach($arr as $v){
$data = explode("|",$v);
$ret[$data[0]] = $data[1];
}
Return $ret;
}
array_walk($p_arr,'find',$p);
array_walk(get_data_arr($k),'find',$p);
$ccode = get_data_arr($k);
echo file_get_contents("http://m.weather.com.cn/data/{$ccode[$k]}.html");
I hope this article will be helpful to everyone’s PHP programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
