首页 > 代码库 > PHP array to xml
PHP array to xml
<?php
define(‘NODE_FORMATE‘, "<%s>%s</%s>");
$testXml = array(
‘SubscribeToVSOPReq‘ => array(
‘ActionType‘ => ‘0‘,
‘OrderId‘ => ‘100000003800000000000000000001‘,
‘UserIDType‘ => ‘0‘,
‘ProductNo‘ => ‘18999999‘,
‘ProductOfferInfo‘ => array(
‘ProductOfferType‘ => ‘0‘,
‘ProductOfferID‘ => ‘123123‘,
‘VSubProdInfo‘ => array(‘VProductID‘ => ‘1350000000000000002130‘),
‘IsExperience‘ => 0,
‘SubscribeType‘ => 0,
),
)
);
function buildXML($arrXML)
{
$res = "";
foreach ($arrXML as $node => $value) {
if (is_array($value)) {
$value = http://www.mamicode.com/buildXML($value);
}
$res .= sprintf(NODE_FORMATE, $node, $value, $node);
}
return $res;
}
var_dump(buildXML($testXml));
?>