note 51240 added to function.xml-parse-into-struct
| From: | php-general at lists dot php dot net | Date: | Thu, 24 Mar 2005 12:36:45 +0000 |
| Subject: | note 51240 added to function.xml-parse-into-struct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86881@lists.php.net to get a copy of this message | ||
[...continue] ...............
// ------------------------------------------------
function _xml_runner( &$content ){
$content = NULL;
$level_tags = array();
while ( $position = next($this->_structure)){
// [1] ...................................................
// if we found "open" tag, so make a recursive tag reading
if ( $position['type'] == 'open' ){
$content[$position['tag']] = NULL;
$this->_xml_runner( $value );
// if it is a second tag in this conteiner, we need to reorganize
// string to array and add second similar tag
if (isset($level_tags[$position['tag']]) &&
$level_tags[$position['tag']] == 1 ){
$intermediate = $content[$position['tag']];
$content[$position['tag']] = array();
$content[$position['tag']][] = $intermediate;
$content[$position['tag']][] = $value;
$level_tags[$position['tag']]++;
}
// if more than two tags in container - then reorganiztion was made, jaust add value
elseif ( isset($level_tags[$position['tag']]) &&
$level_tags[$position['tag']] > 1 ){
$content[$position['tag']][] = $value;
$level_tags[$position['tag']]++;
}
// if tag in container - lets just register it, so we can search duplicates
else {
$content[$position['tag']] = $value;
$level_tags[$position['tag']] = 1;
}
$this->_xml_exit();
}
// [2] ...................................................
// else - if it is closed, just read its content
elseif ( $position['type'] == 'complete' ){
// ... add [VALUE] ..............
if (isset($position['value'])) {
// if it is a second tag in this conteiner, we need to reorganize
// string to array and add second similar tag
if (isset($level_tags[$position['tag']]) &&
$level_tags[$position['tag']] == 1 ){
$intermediate = $content[$position['tag']];
$content[$position['tag']] = array();
$content[$position['tag']][] = $intermediate;
$content[$position['tag']][] = $position['value'];
$level_tags[$position['tag']]++;
}
// if more than two tags in container - then reorganiztion was made, jaust add value
elseif ( isset($level_tags[$position['tag']]) &&
$level_tags[$position['tag']] > 1 ){
$content[$position['tag']][] = $position['value'];
$level_tags[$position['tag']]++;
}
// if tag in container - lets just register it, so we can search duplicates
else {
$content[$position['tag']] = $position['value'];
$level_tags[$position['tag']] = 1;
}
}
// ... add [ATRRIBUTE] ................
elseif (isset($position['attributes']))
$content[$position['tag']] = $position['attributes'];
}
}
return true;
}
// ------------------------------------------------
function _xml_exit() {
// "cdata" or "close" expected
// ( just to go to the end of conteiner )
while ( $position = next($this->_structure) ) {
if ($position['type'] == "close") break;
} return true;
}
// -------------------------------------------------
}// end of class
----
Manual Page -- http://www.php.net/manual/en/function.xml-parse-into-struct.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51240
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51240&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51240&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51240&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51240&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51240&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51240&report=yes
Search -- http://master.php.net/manage/user-notes.php