tags:

views:

38

answers:

1

Hi everybody,

i just have a php array with number that i've "explode" to separate itens,

$arr = array($_POST["fname"]);

$arr = 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

+1  A: 

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.

Jason McCreary
While this _works_ you probably shouldn't be manually constructing the XML like that, as it loses some of flexibility you can get by using a real XML parser/builder
Jamie Wong
@Jaime agreed for a larger XML document. From the OP, the XML seemed trivial and my answer simply modifies existing code.
Jason McCreary
hi, when i explode the original POST this put each element in one postition of the array $arr, it's ok? cause i need the first two in a line the next two one other, etc...my point is do something like this: http://tinypaste.com/d2811 offcourse without the database...
TiagoMartins
I made a lot of complication..you're right thanks
TiagoMartins