note 64528 added to ref.xml
| From: | Niels at quotar dot com | Date: | Mon, 17 Apr 2006 21:35:37 +0000 |
| Subject: | note 64528 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108361@lists.php.net to get a copy of this message | ||
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
----
Server IP: 83.137.20.120
Probable Submitter: 82.161.60.185
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/note/edit/64528
Del: integrated -- http://master.php.net/note/delete/64528/integrated
Del: useless -- http://master.php.net/note/delete/64528/useless
Del: bad code -- http://master.php.net/note/delete/64528/bad+code
Del: spam -- http://master.php.net/note/delete/64528/spam
Del: non-english -- http://master.php.net/note/delete/64528/non-english
Del: in docs -- http://master.php.net/note/delete/64528/in+docs
Del: other reasons-- http://master.php.net/note/delete/64528
Reject -- http://master.php.net/note/reject/64528
Search -- http://master.php.net/manage/user-notes.php