note 60123 added to ref.xml

From: Date: Tue, 27 Dec 2005 13:24:09 +0000
Subject: note 60123 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-100785@lists.php.net to get a copy of this message
<?php there should be more code in front of this...... function arraytoxml($cjxml,$depth=0) { $out=""; foreach($cjxml as $k => $pv){ foreach($pv as $v){ if($depth>=0){ $out.="\n"; for($i=0;$i<$depth;$i++) $out.="\t"; } $out.="<".$k; foreach($v['attributes'] as $ak =>$av) { $out.=' '.$ak.'="'.$av.'"'; } $out.=">"; if($depth>=0) $out.=$this->arraytoxml($v['elements'],$depth+1); else $out.=$this->arraytoxml($v['elements'],-1); foreach($v['values'] as $vv) { if(strpos($vv,"]]>")===false) $vvo="<![CDATA[".$vv."]]>"; else $vvo=str_replace(array(">","<","'",'"','&'), array("&gt;","&lt;","&apos;",'&quot;','&amp;'),$vv); $out.=$vvo; } $out.="</".$k.">"; } } return $out; } } $ix=new q(); $erg =$ix->xmltoarray('<object name="name2">alphatext? <element name="name" id="1"><![CDATA[text abc <de ]]></element> objettext2<element name="name" id="2">text2 </element><element name="name" id="3" /><!-- any --> objekttext</object>'); print_r($erg); $ergt=$ix->arraytoxml($erg); print($ergt); $ergi=$ix->arraytoxml($erg,-1); print($ergi); $erg =$ix->xmltoarray($ergi); print_r($erg); //it produes an array wich can be easiely used by programs without any special cases //its structure is /* [tag] [#] ["attributes"] [attribute]=>string ["values"] [#]=>string ["elements"] [tag] [#] ["attributes"] [attribute]=>string ["values"] [#]=>string ["elements"] [tag] [#] ....... # means any number tag means the tag of the element attribut means the attribut ....... */ //btw. array 2 xml builds the xml from this array, u see the code is simple since the array has no special cases ?> ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60123 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60123&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60123&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100785) next »