<?php
include "image.php";
$con = mysql_connect("127.0.0.1:3307", 'waimai', 'waimai');
mysql_select_db("waimai", $con);
mysql_query('set names utf8', $con);
$file=glob("/data/web/zhua/*.xml");
foreach($file as $spco=>$val){
$data=getinfo($val);
$sql=getsql($data);
if (mysql_query($sql)) {
unset($data['combination']);
print_r($data);
echo '成功插入'.$spco.'条数据'."\n";
} else {
echo $sql,"插入失败了..."; exit;
}
}
function getsql($data){
$sql = "insert into wm_content set ";
foreach ($data as $key => $val) {
$sql .= "$key='" . mysql_real_escape_string($val) . "',";
}
return $sql .= "status=1";
}
function getinfo($file) {
$doc = new DOMDocument();
$doc->load($file); //读取xml文件
$humans = $doc->getElementsByTagName("data"); //取得humans标签的对象数组
foreach ($humans as $key => $human) {
$data['remark'] = '外卖库|'.$human->getElementsByTagName("url")->item(0)->nodeValue;
$data['name'] = $human->getElementsByTagName("name")->item(0)->nodeValue;
$data['area'] = $human->getElementsByTagName("area")->item(0)->nodeValue;
$data['address'] = $human->getElementsByTagName("address")->item(0)->nodeValue;
$data['stmoney'] = $human->getElementsByTagName("stmoney")->item(0)->nodeValue;
$data['time_one'] = $human->getElementsByTagName("opentime")->item(0)->nodeValue;
$comb = $human->getElementsByTagName("combination")->item(0)->nodeValue;
$oudata = json_decode(str_replace(array ('<![CDATA','>'), '', $comb), true);
$data['combination'] = base64_encode(json_encode($oudata));
$phone = $human->getElementsByTagName("mbphone")->item(0)->nodeValue;
$data['mbphone'] = getphone($phone);
$lan = getlatlong($data['address']);
$data['latitude'] = $lan['lat'];
$data['longitude'] = $lan['long'];
$data['source']=1;
return $data;
}
}
function getphone($imgPath) {
$gjPhone = new gjPhone($imgPath);
$gjPhone->getHec();
$horData = $gjPhone->magHorData();
$verData = $gjPhone->magVerData($horData);
$phone = $gjPhone->showPhone($verData);
if (strstr($phone, "/"))
$phone = $gjPhone->showPhone($verData, 2);
return $phone ? $phone : $imgPath;
}
function getlatlong($address = '') {
$key = 'b64856ba2cabeef3e5ef963ad7f87d68';
$url = "http://api.map.baidu.com/geocoder?address=$address&output=json&key=$key&city=北京";
$file = file_get_contents($url);
$out = json_decode($file, true);
if (isset($out['result']['location']['lng'])) {
$latlong['lat'] = $out['result']['location']['lng'];
$latlong['long'] = $out['result']['location']['lng'];
} else {
$latlong['lat'] = '';
$latlong['long'] = '';
}
return $latlong;
}
include "image.php";
$con = mysql_connect("127.0.0.1:3307", 'waimai', 'waimai');
mysql_select_db("waimai", $con);
mysql_query('set names utf8', $con);
$file=glob("/data/web/zhua/*.xml");
foreach($file as $spco=>$val){
$data=getinfo($val);
$sql=getsql($data);
if (mysql_query($sql)) {
unset($data['combination']);
print_r($data);
echo '成功插入'.$spco.'条数据'."\n";
} else {
echo $sql,"插入失败了..."; exit;
}
}
function getsql($data){
$sql = "insert into wm_content set ";
foreach ($data as $key => $val) {
$sql .= "$key='" . mysql_real_escape_string($val) . "',";
}
return $sql .= "status=1";
}
function getinfo($file) {
$doc = new DOMDocument();
$doc->load($file); //读取xml文件
$humans = $doc->getElementsByTagName("data"); //取得humans标签的对象数组
foreach ($humans as $key => $human) {
$data['remark'] = '外卖库|'.$human->getElementsByTagName("url")->item(0)->nodeValue;
$data['name'] = $human->getElementsByTagName("name")->item(0)->nodeValue;
$data['area'] = $human->getElementsByTagName("area")->item(0)->nodeValue;
$data['address'] = $human->getElementsByTagName("address")->item(0)->nodeValue;
$data['stmoney'] = $human->getElementsByTagName("stmoney")->item(0)->nodeValue;
$data['time_one'] = $human->getElementsByTagName("opentime")->item(0)->nodeValue;
$comb = $human->getElementsByTagName("combination")->item(0)->nodeValue;
$oudata = json_decode(str_replace(array ('<![CDATA','>'), '', $comb), true);
$data['combination'] = base64_encode(json_encode($oudata));
$phone = $human->getElementsByTagName("mbphone")->item(0)->nodeValue;
$data['mbphone'] = getphone($phone);
$lan = getlatlong($data['address']);
$data['latitude'] = $lan['lat'];
$data['longitude'] = $lan['long'];
$data['source']=1;
return $data;
}
}
function getphone($imgPath) {
$gjPhone = new gjPhone($imgPath);
$gjPhone->getHec();
$horData = $gjPhone->magHorData();
$verData = $gjPhone->magVerData($horData);
$phone = $gjPhone->showPhone($verData);
if (strstr($phone, "/"))
$phone = $gjPhone->showPhone($verData, 2);
return $phone ? $phone : $imgPath;
}
function getlatlong($address = '') {
$key = 'b64856ba2cabeef3e5ef963ad7f87d68';
$url = "http://api.map.baidu.com/geocoder?address=$address&output=json&key=$key&city=北京";
$file = file_get_contents($url);
$out = json_decode($file, true);
if (isset($out['result']['location']['lng'])) {
$latlong['lat'] = $out['result']['location']['lng'];
$latlong['long'] = $out['result']['location']['lng'];
} else {
$latlong['lat'] = '';
$latlong['long'] = '';
}
return $latlong;
}