采集自国家统计局
http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201504/t20150415_712722.html
有需要的同学自行下载附件,分割入库
文件格式如下
110000,北京市###110100,市辖区###110101,东城区###110102……
数据库方面CREATE TABLE `think_region` (<br>
`id` mediumint(6) unsigned NOT NULL DEFAULT '0',<br>
`pid` mediumint(6) unsigned NOT NULL DEFAULT '0',<br>
`name` varchar(100) NOT NULL DEFAULT '',<br>
`type` tinyint(1) NOT NULL DEFAULT '0',<br>
PRIMARY KEY (`id`),<br>
KEY `type` (`type`)<br>
) ENGINE=MyISAM DEFAULT CHARSET=utf8
控制器方面 $DB = M('Region');<br>
$file = './code.txt';<br>
$content = file_get_contents($file);<br>
$content = think_s2a($content, '###');<br>
$i=0;$addall=array();<br>
foreach ($content as $v) {<br>
$data = think_s2a($v);<br>
switch (true) {<br>
case (preg_match('/\d{2}0000/', $data[0])):<br>
$pid = 0;<br>
$type = 0;<br>
break;<br>
case (preg_match('/\d{4}00/', $data[0])):<br>
$pid = substr($data[0], 0, 2) . '0000';<br>
$type = 1;<br>
break;<br>
default:<br>
$pid = substr($data[0], 0, 4) . '00';<br>
$type = 2;<br>
}<br>
$add = array(<br>
'id' => $data[0],<br>
'pid' => $pid,<br>
'name' => $data[1],<br>
'type' => $type,<br>
);<br>
$rules = array(<br>
array('id', 'require','id必须'),<br>
array('pid', 'require','pid必须'),<br>
array('name', 'require','neme必须'),<br>
array('type', array(0,1, 2), '类型范围', 1, 'in', 1),<br>
array('id', '', '该地区已录入', 1, 'unique', 1),<br>
);<br>
if ($DB->validate($rules)->create($add, 1)) {<br>
$addall[$i]=$DB->data();<br>
$i++;<br>
}<br>
}<br>
$DB->addAll($addall);
地区.zip
( 20.91 KB 下载:106 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool