(.*?)<\/td> | (.*?)<\/td> | (.*?)<\/td><\/tr>/i', $html, $result);
$update = array();
if (isset($result[1]) && isset($result[2]) && isset($result[3])) {
foreach ($result[3] as $k => $v) {
$update['id'] = $this->id($result[1][$k], 12);
$update['code'] = $result[2][$k];
$update['name'] = strip_tags($v);
$update['town_id'] = $town;
$update['county_id'] = $county;
$update['city_id'] = $city;
$update['province_id'] = $province;
$update['area'] = $province . ',' . $city . ',' . $county . ',' . $town;
$this->pinyin($update);
$this->upinto('area/village', $update['id'], $update);
}
}
}
public function id($id, $len = 6)
{
return Dever::load('area/api')->code($id, $len);
}
public function pinyin(&$update)
{
if (Dever::import('pinyin') && $update['name']) {
$update['pinyin'] = Dever::getPinyin($update['name']);
$update['pinyin_first'] = Dever::getPinyinFirst($update['name']);
}
}
public function setLevelCounty(&$update)
{
$num = substr($update['id'], 4);
# type = 1城区 2郊区 3县城 4经济技术开发 5县级市
if ($update['name'] == '门头沟区') {
$update['type'] = 2;
$update['level'] = 2;
} elseif ($num <= 10) {
$update['type'] = 1;
$update['level'] = 1;
} elseif ($num > 10 && $num <= 20) {
$update['type'] = 2;
$update['level'] = 2;
} elseif ($num > 20 && $num <= 70) {
$update['type'] = 3;
$update['level'] = 3;
} elseif ($num > 70 && $num <= 80) {
$update['type'] = 4;
$update['level'] = 2;
} elseif ($num >= 80) {
$update['type'] = 5;
$update['level'] = 2;
}
}
public function upinto($table, $id, $data)
{
$info = Dever::db($table)->one($id);
if (!$info) {
return Dever::db($table)->insert($data);
} else {
$data['where_id'] = $info['id'];
return Dever::db($table)->update($data);
}
}
private function html($url)
{
$html = Dever::curl($url);
//$html = Dever::convert($html, "UTF-8", "GBK");
$html = preg_replace('//', '', $html); // 去掉HTML注释
$html = preg_replace('/\s+/', ' ', $html); // 清除多余的空格
$html = preg_replace('/>\s', '><', $html); // 去掉标记之间的空格
return $html;
}
}
|