ParseOut_class.php
资源名称:BBWPS.rar [点击查看]
上传用户:yttaitong
上传日期:2009-05-10
资源大小:128k
文件大小:3k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
PHP
- <?PHP
- /*
- [BBWPS!] (C)2006-2010 小蜜蜂版权所有.
- This is NOT a freeware, use is subject to license terms
- 时间:2007年12月
- 描述:
- */
- class OutParse{
- var $url;
- var $data;
- var $items;
- var $xml_parser;
- var $depth="2";
- var $tag="OUT";
- var $prev_tag;
- var $marker="2";
- var $event;
- var $item_index;
- function __construct($Out_url=""){
- $this->OutParse($Out_url);
- }
- function OutParse($Out_url=NULL){
- if(get_cfg_var("allow_url_fopen")){
- $fp=fopen($Out_url,"r");
- if($fp){
- while(!feof($fp)){$this->data.=fgets($fp,4096);}
- }
- fclose($fp);
- }
- else{$this->data=openFileRemote($Out_url);}
- if($this->data){
- if(function_exists("xml_parser_create")){
- if(!$this->ParseXML()){
- return null;
- }
- }
- else{
- $this->ParseReg();
- }
- }
- else{
- return null;
- }
- }
- function GetItems(){
- return $this->items;
- }
- function GetVersion(){
- return $this->version;
- }
- function startElement($parser, $name, $attribs){
- $this->depth++;
- $this->tag=$name;
- switch($name){
- case "OUT":
- $this->event=$name;
- $this->version=$attribs["VERSION"];
- break;
- case "ITEM":
- $this->item_index++;
- $this->event=$name;
- $this->marker=$this->depth+1;
- break;
- default:
- return NULL;
- }
- }
- function endElement($parser, $name){
- $this->depth--;
- return null;
- }
- function characterData($parser, $data){
- if( $this->event=="ITEM" && $this->marker==$this->depth ){
- if($this->prev_tag==$this->tag){
- $this->items[$this->item_index][$this->tag].=rawurldecode($data);
- }
- else{
- $this->items[$this->item_index][$this->tag]=rawurldecode($data);
- }
- }
- $this->prev_tag=$this->tag;
- }
- function ParseXML(){
- $this->xml_parser = xml_parser_create();
- xml_set_object($this->xml_parser, &$this);
- xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, 1);
- xml_set_element_handler($this->xml_parser, "startElement", "endElement");
- xml_set_character_data_handler($this->xml_parser, "characterData");
- if (!xml_parse($this->xml_parser, $this->data)){
- return false;
- }
- return true;
- }
- function ParseReg(){
- preg_match_all("/<item>(.*?)</item>/is",$this->data,$itemArray);
- foreach ($itemArray[1] as $item){
- $this->item_index++;
- preg_match_all("/<([a-zA-Z]+)>(.*?)</\1>/is",$item,$tagArray);
- foreach ($tagArray[2] as $key=>$data){
- $this->items[$this->item_index][strtoupper(trim($tagArray[1][$key]))]=rawurldecode($data);
- }
- }
- }
- }
- ?>