note 111394 added to class.simplexmlelement

From: Date: Fri, 15 Feb 2013 13:59:41 +0000
Subject: note 111394 added to class.simplexmlelement
Groups: php.notes 
Request: Send a blank email to php-notes+get-193645@lists.php.net to get a copy of this message
xml to object conversion function : <?php /** @param: $xml: SimpleXMLElement $force: set to true to always create 'text', 'attribute', and 'children' even if empty @return object with attributs: (string) name: XML tag name (string) text: text content of the attribut name (array) attributes: array witch keys are attribute key and values are attribute value (array) children: array of objects made with xml2obj() on each child **/ function xml2obj($xml,$force = false){ $obj = new StdClass(); $obj->name = $xml->getName(); $text = trim((string)$xml); $attributes = array(); $children = array(); foreach($xml->attributes() as $k => $v){ $attributes[$k] = (string)$v; } foreach($xml->children() as $k => $v){ $children[] = xml2obj($v,$force); } if($force or $text !== '') $obj->text = $text; if($force or count($attributes) > 0) $obj->attributes = $attributes; if($force or count($children) > 0) $obj->children = $children; return $obj; } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 109.190.16.174 ---- Manual Page -- http://php.net/manual/en/class.simplexmlelement.php Edit -- https://master.php.net/note/edit/111394 Del: integrated -- https://master.php.net/note/delete/111394/integrated Del: useless -- https://master.php.net/note/delete/111394/useless Del: bad code -- https://master.php.net/note/delete/111394/bad+code Del: spam -- https://master.php.net/note/delete/111394/spam Del: non-english -- https://master.php.net/note/delete/111394/non-english Del: in docs -- https://master.php.net/note/delete/111394/in+docs Del: other reasons-- https://master.php.net/note/delete/111394 Reject -- https://master.php.net/note/reject/111394 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193645) next »