读取团购网站的api的php程序 |
时间:2015-01-23 来源:西部数据 作者:西部数据 |
|
读取团购网站的api的php教程程序,代码如下:
- $arr = array(
- array("http://www.meituan.com/api/deals/hao123","url","美团网"),
-
- );
-
- class AminoAcid {
- var $name;
- var $symbol;
- var $code;
- var $type;
- function AminoAcid ($aa){
- foreach ($aa as $k=>$v)
- $this->$k = $aa[$k];
- }
- }
- function readDatabase($filename,$label){
- $data = implode("",file($filename));
- $parser = xml_parser_create();
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, $data, $values, $tags);
- xml_parser_free($parser);
- foreach ($tags as $key=>$val) {
- if ($key == $label) {
- $molranges = $val;
- for ($i=0; $i < count($molranges); $i+=2) {
- $offset = $molranges[$i] + 1;
- $len = $molranges[$i + 1] - $offset;
- $tdb[] = parseMol(array_slice($values, $offset, $len));
- }
- } else {
- continue;
- }
- }
- return $tdb;
- }
- function parseMol($mvalues){
- for ($i=0; $i < count($mvalues); $i++) {
- $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
- }
- return new AminoAcid($mol);
- }
-
- foreach($arr as $key => $value){
- $r = readDatabase($value[0],$value[1]);
- print_r($r);
- }
|
|
|
|