note 57864 added to ref.simplexml

From: Date: Mon, 17 Oct 2005 09:00:48 +0000
Subject: note 57864 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-97107@lists.php.net to get a copy of this message
Thanks to Daniel Faivre! Great work! I modified it to an array filled with ISO-8859-1 text and not UTF-8. Haven't tested it in detail - so be cautious! Tobias <?php /** * Convert SimpleXMLElement object to ISO array * Copyright Daniel FAIVRE 2005 - www.geomaticien.com * Copyleft GPL license * * Modifications by Tobias Wantzen * Returned array will contain single-byte ISO-8859-1 using utf8_decode() */ function simplexml2ISOarray($xml) { if (get_class($xml) == 'SimpleXMLElement') { $attributes = $xml->attributes(); foreach($attributes as $k=>$v) { if ($v) $a[$k] = (string) $v; } $x = $xml; $xml = get_object_vars($xml); } if (is_array($xml)) { if (count($xml) == 0) return (string) $x; // for CDATA foreach($xml as $key=>$value) { $r[$key] = simplexml2ISOarray($value); // original line instead of the following if statement: //$r[$key] = simplexml2ISOarray($value); if ( !is_array( $r[$key] ) ) $r[$key] = utf8_decode( $r[$key] ); } if (isset($a)) $r['@'] = $a; // Attributes return $r; } return (string) $xml; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57864 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57864&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57864&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97107) next »