Array to XML in Php (using DOM)
i just have a php array with number that i've "explode" to separate itens,
$arr = array($_POST["fname"]);
$a开发者_StackOverflow社区rr = explode(',', $_POST['fname']);
$parentesis;
$parentesis2;
for ($i = 0; $i < sizeof($arr); $i+=2){
`$parentesis = substr($arr[$i], 1);`
`$parentesis2 = substr($arr[$i+1], 0,-1);`
actually arays are $arr[0] = 435567899
, $arr[1] = -78904452
, $arr[2] = 345688
, $arr[3] = -3456778
and i need put this "numbers" in xml,
something like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rotas>
<routa>
<p x="4060092" y="-870872498" />
<p x="4062229178" y="-865310669" />
</routa>
</rotas>
so postion zero and one in a line, the next two postions in other, etc..
thanks for help
I think you have it. I would just build an XML string inside your loop, like so:
$routa = '';
for ($i = 0; $i < sizeof($arr);){
$routa .= '<p x="' . $arr[++$i] . '" y="' . $arr[++$i] . '" />';
}
Keep in mind this assumes matching pairs in your array. Just stuff $routa
in your XML schema when your ready to output.
精彩评论