note 47866 added to function.xml-parse-into-struct

From: Date: Fri, 03 Dec 2004 12:32:58 +0000
Subject: note 47866 added to function.xml-parse-into-struct
Groups: php.notes 
Request: Send a blank email to php-notes+get-81310@lists.php.net to get a copy of this message
If you have de XML: <?xml version="1.0" encoding="iso-8859-1"?> <teste> <teste> <teste> </teste> </teste> </teste> this function will return this tags: Array ( [teste] => Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 ) ) With this function (right below) will convert the struc to OPEN and CLOSE concept. The New Struct: Array ( [teste] => Array ( [0] => 0 [1] => 4 [2] => 1 [3] => 3 [4] => 2 ) ) The Function: /** * @return bool * @param xml_array $values * @param xml_array[reference] $tags * @desc Reconstruct xml_parse_into_struct */ function reconstruct_tag($values, &$tags) { unset($return); foreach ($tags as $tkey => $tvalue) { foreach ($tvalue as $vvalue) { if ($values[$vvalue]['type'] == 'open' or $values[$vvalue]['type'] == 'complete') { $return[$tkey][] = $vvalue; } if ($values[$vvalue]['type'] == 'open') { foreach ($tvalue as $tv_value) { if ($values[$tv_value]['type'] == 'close' and $values[$tv_value]['level'] == $values[$vvalue]['level']) { $return[$tkey][] = $tv_value; } } } } } $tags = $return; return (bool) $tags; } Ahh, DO NOT forget this comment: jukkaho at mail dot student dot oulu dot fi 29-Jun-2004 12:17 Everyone seems to forget the return value of this function (including people making examples!), but it is there for a reason: 0 if failed (invalid XML), 1 if succeeded. Return value really is an integer, be careful with those === operators. ---- 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+47866 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47866&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47866&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47866&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47866&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47866&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47866&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47866&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81310) next »