note 101016 added to book.simplexml

From: Date: Sat, 20 Nov 2010 15:41:38 +0000
Subject: note 101016 added to book.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-174220@lists.php.net to get a copy of this message
function NXmlToArray( $mXml, $bInlineAttr=true, $bOneChildTypeInline=true ){ static $sAttrChildId = "id"; static $mOutputEncoding = "cp1251"; if( !is_object($mXml) ){ return $mXml; } $return = array(); // parse attributes $arrAttr = array(); $arrTmpAttr = $mXml->attributes(); foreach( $arrTmpAttr as $sCode=>$mValue ){ $sValue = trim( mb_convert_encoding( (string)$mValue, $mOutputEncoding, "utf8" ) ); if( $bInlineAttr ){ $return[$sCode] = $sValue; } else { $return["@attr"][$sCode] = $sValue; } } // parse child (value) $arrChild = $mXml->children(); if( count($arrChild)==0 ){ $sValueTmp = trim( mb_convert_encoding( (string)$mXml, $mOutputEncoding, "utf8" ) ); $return["value"] = $sValueTmp; } else { foreach( $arrChild as $sCode=>$child ){ $value = NXmlToArray( $child, $bInlineAttr, $bOneChildTypeInline ); if( isset($value[$sAttrChildId]) ){ $return[$sCode][$value[$sAttrChildId]] = $value; continue; } if( count($value)==1 && isset($value["value"]) ){ $value = $value["value"]; } if( isset($return[$sCode]) ){ if( !is_array($return[$sCode]) || !isset($return[$sCode][0]) ){ $return[$sCode] = array( $return[$sCode] ); } $return[$sCode][] = $value; } else { $return[$sCode] = $value; } } if( $bOneChildTypeInline ){ if( count($return)==1 ){ $return = reset($return); } } } return $return; } ---- Server IP: 69.147.83.197 Probable Submitter: 77.35.20.213 ---- Manual Page -- http://www.php.net/manual/en/book.simplexml.php Edit -- https://master.php.net/note/edit/101016 Del: integrated -- https://master.php.net/note/delete/101016/integrated Del: useless -- https://master.php.net/note/delete/101016/useless Del: bad code -- https://master.php.net/note/delete/101016/bad+code Del: spam -- https://master.php.net/note/delete/101016/spam Del: non-english -- https://master.php.net/note/delete/101016/non-english Del: in docs -- https://master.php.net/note/delete/101016/in+docs Del: other reasons-- https://master.php.net/note/delete/101016 Reject -- https://master.php.net/note/reject/101016 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174220) next »