note 54625 added to ref.xml
| From: | alper at sabanciuniv dot edu | Date: | Sun, 10 Jul 2005 11:56:47 +0000 |
| Subject: | note 54625 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91736@lists.php.net to get a copy of this message | ||
vladson has written a good code to converting an xml to an array. It is a good function but it is
not work properly if xml elements has an attribute. I have cahanged the code to work properly when
it has attributes.
The code is:
function xml2array($text) {
$reg_exp = '/<(\w+)[^>]*>(.*?)<\/\\1>/s';
preg_match_all($reg_exp, $text, $match);
foreach ($match[1] as $key=>$val) {
if ( preg_match($reg_exp, $match[2][$key]) ) {
$array[$val][] = xml2array($match[2][$key]);
} else {
$array[$val] = $match[2][$key];
}
}
return $array;
}
Alper Sari
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54625
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54625&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54625&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54625&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54625&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54625&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54625&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54625&report=yes
Search -- http://master.php.net/manage/user-notes.php