0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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
@Jaime agreed for a larger XML document. From the OP, the XML seemed trivial and my answer simply modifies existing code.
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: tinypaste.com/d2811 offcourse without the database...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.