Okay, so I'm working on a PHP script to ease my creation of very large environment related arrays for Yumé:tED; however, I'm having difficulty with two things.
For one, I have a logic issue somewhere in my code as my test data output looks like this:
Code:
As you can see, it has bizarre extra commas at the beginning of the 2nd group of array values on up. My code is:
Code:
and my test input is
Code:
Also, as you may or may not notice:
Code:
The above line does nothing whatsoever. It's my attempt at simply fixing the output because I couldn't figure out what was causing the issue in the first place.
So, what's causing the error and why won't str_replace do its job?
For one, I have a logic issue somewhere in my code as my test data output looks like this:
Code:
{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
As you can see, it has bizarre extra commas at the beginning of the 2nd group of array values on up. My code is:
Code:
<?php
$data = file_get_contents("./arraygen/data.txt");
$dataarray = explode("|", $data);
for($i = 0; $i < count($dataarray); $i++)
{
$tmp = explode(" ",$dataarray[$i]);
for($j = 0; $j < count($tmp); $j++)
{
$tmpstr = $tmp[$j];
for($z = 0; $z < strlen($tmpstr); $z++)
{
$finarray[$j] .= substr($tmpstr, $z, 1).",";
}
}
$finstring = implode("", $finarray);
echo($finstring); //Ignore this and the next two lines, they're just debug I left in.
echo("\n");
echo("\n");
$finstring = substr($finstring, 0, strlen($finstring)-1);
$finstring = "{".$finstring."}";
$ultarray[] = $finstring;
$finstring = NULL;
$finarray = NULL;
}
$ultstring = implode (",", $ultarray);
$ultstring = "{".$ultstring."};";
$ultstring = str_replace(',,', "", $ultstring);
$file = fopen("./arraygen/result.txt", "w");
fwrite($file, $ultstring);
fclose($file);
?>
and my test input is
Code:
000000000000 000000000000 000000000000 000000000000 000000000000|
000000000000 000000000000 000000000000 000000000000 000000000000|
000000000000 000000000000 000000000000 000000000000 000000000000|
000000000000 000000000000 000000000000 000000000000 000000000000|
000000000000 000000000000 000000000000 000000000000 000000000000|
000000000000 000000000000 000000000000 000000000000 000000000000|
000000000000 000000000000 000000000000 000000000000 000000000000
Also, as you may or may not notice:
Code:
$ultstring = str_replace(',,', "", $ultstring);
The above line does nothing whatsoever. It's my attempt at simply fixing the output because I couldn't figure out what was causing the issue in the first place.
So, what's causing the error and why won't str_replace do its job?