ohdang888 Posted March 17, 2009 Share Posted March 17, 2009 i have an xml file: http://api.betacie.com/view/last?key=readonly&language=en and i want to grab it, and put it in an array. How do i go about doing this? Thanks. Link to comment https://forums.phpfreaks.com/topic/149755-xml-handling/ Share on other sites More sharing options...
DJ Zen Masta K Posted March 17, 2009 Share Posted March 17, 2009 this help? http://www.phpclasses.org/browse/package/4954.html Link to comment https://forums.phpfreaks.com/topic/149755-xml-handling/#findComment-786383 Share on other sites More sharing options...
ohdang888 Posted March 17, 2009 Author Share Posted March 17, 2009 its not working.... its putting weird elements in... http://bookmark.socialapps.sclek.com/include/index.php This is the code: <? $content = file_get_contents('http://api.betacie.com/view/last/1?key=readonly&language=en'); $parser = new XmlParser(); $result = $parser->parse($content); print_r($result); /** * @desc XML Parser Class (returns xml data as array) * @author Eren Ezg端 [eezgu at eezgu.com] * * @example * $parser = new XmlParser($xml_input); * $result = $parser->parse(); * @example * $parser = new XmlParser(); * $result = $parser->parse($xml_input); */ class XmlParser{ var $xml_parser; var $xml_input=null; var $elements = array(); var $index_arr = array(); var $ref; /** * @desc Constructor * @param string */ function XmlParser($xml=null){ $this->xml_input = $xml; } /** * @desc Parsing function * @param string */ function parse($xml=null){ $this->xml_input = $xml; if($this->xml_input==null){ return false; } $this->xml_parser = xml_parser_create(); xml_set_object($this->xml_parser, $this); 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->xml_input)){ return false; } xml_parser_free($this->xml_parser); return $this->elements; } function startElement($parser,$tagName,$attrs){ $this->ref=&$this->elements; foreach($this->index_arr as $index){ $this->ref = &$this->ref[$index]; } $this->ref[] = array('tag'=>$tagName,'attr'=>$attrs,'data'=>'','children'=>array()); $i = end(array_keys($this->ref)); array_push($this->index_arr,$i); array_push($this->index_arr,'children'); } function characterData($parser, $data){ $index_arr = $this->index_arr; array_pop($index_arr); $ref=&$this->elements; foreach($index_arr as $index){ $ref = &$ref[$index]; } $ref['data']=$data; } function endElement($parser,$tagName){ array_pop($this->index_arr); array_pop($this->index_arr); } } ?> Link to comment https://forums.phpfreaks.com/topic/149755-xml-handling/#findComment-787101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.