Version: v.1.0
Type: Function
Category: HTTP
License: GNU General Public License
Description: Convert a php class to an xml string.
<?php function object2xml($obj){ $ser = serialize($obj); if($temp = split(""",$ser)){ $CName = $temp[1]; } if(ereg("{+.+}",$ser,$temp)){ $ser = $temp[0]; } $ser = get_object_vars($obj); $vars = array_values($ser); $keys = array_keys($ser); $xml = "<?xml version="1.0"?>n"; $xml .= "<$CName>n"; $n = 0; for($i = 0;$i < count($keys);$i++){ if(ereg("[array]",$vars[$i])){ $vars[$i] = $arrays[$n++]; } $xml .= "t<".$keys[$i].">"; if(is_array($vars[$i])){ $temp[0] = array_keys($vars[$i]); $temp[1] = array_values($vars[$i]); for($l = 0;$l < count($temp[0]);$l++){ if($temp[1][$l]){ $xml .= "ntt<".$temp[0][$l].">".$temp[1][$l]."</".$temp[0][$l].">"; } if($l + 1 == count($vars[$i])){ $xml .= "nt"; } } }else{ $xml .= $vars[$i]; } $xml .= "</".$keys[$i].">n"; } $xml .= "</$CName>n"; return $xml; } ?>