note 64528 deleted from ref.xml by bjori

From: Date: Tue, 18 Apr 2006 07:50:58 +0000
Subject: note 64528 deleted from ref.xml by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108386@lists.php.net to get a copy of this message
Note Submitter: Niels at quotar dot com ---- A little script to push a simple XML in a array. <?php function fXMLParser($sXML){ $hParser = xml_parser_create(); xml_parse_into_struct($hParser, $sXML, $aValue); xml_parser_free($hParser); return fXMLtransform($aValue); } function fXMLtransform($aHaystack) { if ((!empty($aHaystack)) AND (is_array($aHaystack))) { foreach ($aHaystack as $mJunk => $aValue) { if ($aValue["type"] == "complete") { $aTransform[strtolower($aValue["tag"])]=$aValue["value"]; } } } return ($aTransform); } $sXML ='<?xml version="1.0" encoding="ISO-8859-1"?> <qi:spider xmlns:qi="http://top.quotar.com/index/"> <qi:url>www.quotar.com</qi:url> <qi:urlid>1467</qi:urlid> <qi:time>1145294893</qi:time> <qi:etag></qi:etag> <qi:store>/data/cache/f2/a1/65/a0</qi:store> <qi:content><![CDATA[ .... some content ... ]]></qi:content> </qi:spider>'; $aResult = fXMLParser($sXML); var_dump($aResult); ?> output: =================== array(6) { ["QI:URL"]=> string(20) "www.quotar.com" ["QI:URLID"]=> string(4) "1467" ["QI:TIME"]=> string(10) "1145294893" ["QI:ETAG"]=> NULL ["QI:STORE"]=> string(23) "/data/cache/f2/a1/65/a0" ["QI:CONTENT"]=> string(5197) " ... some content ... " } HTH, regards, Niels

« previous php.notes (#108386) next »