Created
December 8, 2018 08:53
-
-
Save eto4detak/7544f6d2ee0d7253f7a23539d5b097dc to your computer and use it in GitHub Desktop.
php parse xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function RecurseXML2($xml = '') | |
{ | |
function RecurseXML($xml, &$vals, $parent = "") | |
{ | |
$childs = 0; | |
$child_count = -1; # Not realy needed. | |
$arr = array(); | |
foreach ($xml->children() as $key => $value) { | |
if (in_array($key, $arr)) { | |
$child_count++; | |
} else { | |
$child_count = 0; | |
} | |
$arr[] = $key; | |
$k = ($parent == "") ? "$key.$child_count" : "$parent.$key.$child_count"; | |
foreach($value->attributes() as $a => $b) { | |
$vals[$k.'.'.$a] = (string) $b; | |
} | |
$childs = RecurseXML($value, $vals, $k); | |
if ($childs == 0) { | |
$vals[$k] = (string) $value; | |
} | |
} | |
return $childs; | |
} | |
$vals = array(); | |
RecurseXML($xml, $vals); | |
return $vals; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment