search
Homephp教程php手册最新县及县以上行政区划代码(截止2014年10月31日)

采集自国家统计局
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元

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!