/** * Formats the return response based upon the content types. * * @param string $contents An array where keys are nodes and values are the node data * @return array */ public function return_response($contents) { switch ($this->format) { case 'xml': if (preg_match('/<response>/', $contents)) { return $contents; } else { $xml = new XmlConstruct('response'); $xml->fromArray($contents); return $xml->getDocument(); return $xml->output(); } break; case 'json': if (preg_match('/response :/', $contents)) { return $contents; } else { $jsonData = json_encode($contents); return json_decode($jsonData); } break; case 'html': if (preg_match('/\\<dt\\>response_code\\<\\/dt\\>/', $contents)) { return $contents; } else { $htmlOut = ''; foreach ($contents as $key => $val) { $htmlOut .= "<ul>{$key}<li>{$val}</li></ul>\n"; } return $htmlOut; } break; } }
public static function array2xml(array $data) { $obj = new XmlConstruct(); $obj->fromArray($data); $result = trim($obj->getDocument()); return $result; }