PHP 8.5.0 Beta 1 available for testing

Voting

: min(seven, nine)?
(Example: nine)

The Note You're Voting On

desk_ocean at msn dot com
17 years ago
make some modify from Sergey Aikinkulov's note

<?php
function xml2assoc(&$xml){
$assoc = NULL;
$n = 0;
while(
$xml->read()){
if(
$xml->nodeType == XMLReader::END_ELEMENT) break;
if(
$xml->nodeType == XMLReader::ELEMENT and !$xml->isEmptyElement){
$assoc[$n]['name'] = $xml->name;
if(
$xml->hasAttributes) while($xml->moveToNextAttribute()) $assoc[$n]['atr'][$xml->name] = $xml->value;
$assoc[$n]['val'] = xml2assoc($xml);
$n++;
}
else if(
$xml->isEmptyElement){
$assoc[$n]['name'] = $xml->name;
if(
$xml->hasAttributes) while($xml->moveToNextAttribute()) $assoc[$n]['atr'][$xml->name] = $xml->value;
$assoc[$n]['val'] = "";
$n++;
}
else if(
$xml->nodeType == XMLReader::TEXT) $assoc = $xml->value;
}
return
$assoc;
}
?>

add else if($xml->isEmptyElement)
may be some xml has emptyelement

<< Back to user notes page

To Top