Why is my small PHP script not working?
<p>I am writing a script that takes information entered in this format:</p>

<pre><code>John Smith
123 Fake St
Riverwood, 11234
http://google.com
</code></pre>

<p>and turns it into</p>

<pre><code>&lt;location id='1'&gt;
   name='John Smith',
   address='123 Fake St',
   city='Riverwood',
   zip=' 11234',
   website='http://google.com'
&lt;/location&gt;
</code></pre>

<p>Here is the code:</p>

<pre><code>$locations = $_POST['locations'];
$data = explode("\n", $locations);
$dataBlocks = explode("\n\n", $locations);
$num = 1;

for ($i=0; $i&lt;count($dataBlocks); $i++) {

    $name = $data[0];
    $address = $data[1];
    $data2 = explode(',', $data[2]);
    $city = $data2[0];
    $zip = $data2[1];
    $website = $data[3];

    $xml = ("&lt;location id='$num'&gt;
                    name='$name',
                    address='$address',
                    city='$city',
                    zip='$zip',
                    website='$website'
             &lt;/location&gt;");

    $num++;

}
</code></pre>

<p>Now, the above works for one block of info, but when I have 2 or more blocks like so:</p>

<pre><code>John Smith
123 Fake St
Riverwood, 11234
http://google.com

Peter Gunderson
345 Some St
Woodsdale, 44566
http://yahoo.com
</code></pre>

<p>Then I get this output:</p>

<pre><code>&lt;location id='1'&gt;
   name='John Smith',
   address='123 Fake St',
   city='Riverwood',
   zip=' 11234',
   website='http://google.com'
&lt;/location&gt;

&lt;location id='2'&gt;
   name='John Smith',
   address='123 Fake St',
   city='Riverwood',
   zip=' 11234',
   website='http://google.com'
&lt;/location&gt;
</code></pre>

<p>I know why this is, it's because I am defining these variables:</p>

<pre><code>$name = $data[0];
$address = $data[1];
$data2 = explode(',', $data[2]);
$city = $data2[0];
$zip = $data2[1];
$website = $data[3];
</code></pre>

<p>based on there places in the $data array. So, even though I'm using a loop the values of those variables are always the same. For example: whereas for John Smith the $name variable should have a value of $data[0], for Peter Gunderson the name variable should have a value of $data[5]. But now it's $data[0] for both. Hence the output is showing the same name, address, etc. for every info block entered.</p>

<p>So the question is, how can this script be modified so that the output will show unique results for every info block and not just repeat the first one?</p>

<h2>EDIT</h2>

<p>@gazler your code gives me this output for the above example:</p>

<pre><code>&lt;location id='1'&gt;
                    name='John Smith',
                    address='123 Fake St',
                    city='Riverwood',
                    zip=' 11234',
                    website='http://google.com'
&lt;/location&gt;

&lt;location id='2'&gt;
                    name='',
                    address='Peter Smith',
                    city='',
                    zip='',
                    website='Woodsdale, 44566'
&lt;/location&gt;
</code></pre>
