PHP File: test.php is a generic communication class
$code, ' message ' = $message, ' data ' = $data, ' if ($type = = ' json ') {Self::json ($code, $message, $data); exit;} ElseIf ($type = = ' array ') {var_dump ($result);} elseif ($type = = ' xml ') {Self::xmlencode ($code, $message, $data); exit;} else {//todo}}/*** output Communication data as JSON * @param integer $code Status code * @param string $message message * @param array $data data * Return St Ring*/public static function json ($code, $message = ", $data = Array ()) {if (!is_numeric ($code)) {return ';} $result = Array (' Code ' = $code, ' message ' = $message, ' data ' = $data); echo Json_encode ($result); exit;} /*** output Communication data as XML * @param integer $code Status code * @param string $message message * @param array $data data * return string*/public STA Tic function Xmlencode ($code, $message, $data = Array ()) {if (!is_numeric ($code)) {return ';} $result = Array (' Code ' = $code, ' message ' = = $message, ' data ' = $data,); Header ("Content-type:text/xml"); $xml = "
\ n "; $xml. ="
\ n "; $xml. = Self::xmltoencode ($result); $xml. ="
"; Echo $xml;} public static function Xmltoencode ($data) {$xml = $attr = ""; foreach ($data as $key + = $value) {if (Is_numeric ($key)) {$a TTR = "id= ' {$key} '"; $key = "Item";} $xml. = "<{$key} {$attr}>"; $xml. = Is_array ($value)? Self::xmltoencode ($value): $value; $xml. = "
\ n ";} return $xml;}}
Testxml&json.php generates XML and JSON by calling the show () method of the test class
1, ' name ' = ' David '); Response::show (+, ' success ', $data);
This allows an app developer to choose whether to generate XML data or JSON data by assigning different values to the last parameter of the show () function.
Parameters for get requests over HTTP requests:
Http://localhost/testxml&json.php?format=xml This is the URL to generate the XML