note 87304 modified in function.xml-parse-into-struct by thiago

From: Date: Mon, 26 Oct 2009 13:39:25 +0000
Subject: note 87304 modified in function.xml-parse-into-struct by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162101@lists.php.net to get a copy of this message
Here's another attempt at dealing with rebuilding the xml from the array. I'm basically preventing certain tags from being self closing by just checking for them explicitly (sure wish expat didn't interpret <textarea /> and <textarea></textarea> the same way (as "complete" tags). <?php function array2xml($xmlary){ $o=''; foreach($xmlary as $tag ){ if($tag['tag'] == 'textarea' && !isset($tag['value'])){ //fake a value so it won't self close $tag['value']=''; } //tab space: $t = ''; for($i=1; $i < $tag['level'];$i++){ $t.="\t"; } switch($tag['type']){ case 'complete': case 'open': $o.=$t.'<'.$tag['tag']; if(isset($tag['attributes'])){ foreach($tag['attributes'] as $attr=>$aval){ $o.=' '.$attr.'="'.$aval.'"'; }//foreach }//attributes if($tag['type'] == 'complete'){ if(!isset($tag['value'])){ $o .= ' />'."\n"; } else { $o .= '>'."\n".$t.$tag['value']."\n".$t.'</'.$tag['tag'].'>'."\n"; } }else{ $o .= '>'."\n"; } break; case 'close': $o .= $t.'</'.$tag['tag'].'>'."\n"; break; case 'cdata': $o .= $t.$tag['value']."\n"; break; }//switch }//foreach } ?> --was-- Here's another attempt at dealing with rebuilding the xml from the array. I'm basically preventing certain tags from being self closing by just checking for them explicitly (sure wish expat didn't interpret <textarea /> and <textarea></textarea> the same way (as "complete" tags). <? function array2xml($xmlary){ $o=''; foreach($xmlary as $tag ){ if($tag['tag'] == 'textarea' && !isset($tag['value'])){ //fake a value so it won't self close $tag['value']=''; } //tab space: $t = ''; for($i=1; $i < $tag['level'];$i++){ $t.="\t"; } switch($tag['type']){ case 'complete': case 'open': $o.=$t.'<'.$tag['tag']; if(isset($tag['attributes'])){ foreach($tag['attributes'] as $attr=>$aval){ $o.=' '.$attr.'="'.$aval.'"'; }//foreach }//attributes if($tag['type'] == 'complete'){ if(!isset($tag['value'])){ $o .= ' />'."\n"; } else { $o .= '>'."\n".$t.$tag['value']."\n".$t.'</'.$tag['tag'].'>'."\n"; } }else{ $o .= '>'."\n"; } break; case 'close': $o .= $t.'</'.$tag['tag'].'>'."\n"; break; case 'cdata': $o .= $t.$tag['value']."\n"; break; }//switch }//foreach } ?> http://php.net/manual/en/function.xml-parse-into-struct.php

« previous php.notes (#162101) next »