My goal here is to open temp.php, explode by ### (line terminator), then by %% (field terminator). Change a specific field, on a specific line, then implode everything back together and save it.
There are a couple variables at play here:
row = the target row number
target = the target field/column number
nfv = the info that i want to place into the target field
Im using the counter $i to count until i get to the desired row. Then counter $j to count til i get to my desired field/target. So far this gives me an error for invalid implode arguments, or doesn't save any data at all. Im sure there are a couple things wrong, but i am frustrated and lost.
<?
$row = $_GET['row'];
$nfv = $_GET['nfv'];
$target = $_GET['target'];
$data = file_get_contents("temp.php");
$csvpre = explode("###", $data);
$i = 0;
$j = 0;
    foreach ( $csvpre AS $key => $value){
     $i++;
     if($i == $row){
      $info = explode("%%", $value);
       foreach ( $info as $key => $value ){ 
        $j++;
         if($j == "$target"){
          $value = $nfv;
         }
       }
      $csvpre[$key] = implode("%%", $info);
     }   
    }
$save = implode("###", $csvpre);
$fh = fopen("temp.php", 'w') or die("can't open file");
fwrite($fh, $save);
fclose($fh);
header("Location: data.php");
?>
If someone can tell what is wrong with this, please be detailed so i can learn why its not working.
Here is some sample csv data for testing
1%%4%%Team%%40%%75###2%%4%%Individual%%15%%35###3%%4%%Stunt Group%%50%%150###4%%4%%Coed Partner Stunt%%50%%150###5%%4%%Mascot%%15%%35###6%%8%%Team%%40%%75###7%%8%%Stunt Group%%50%%150###8%%8%%Coed Partner Stunt%%50%%150###9%%3%%Team%%40%%75###10%%1%%Team%%40%%75###11%%1%%Solo%%15%%35###12%%1%%Duet%%50%%150###13%%2%%Team%%50%%50###14%%2%%Solo%%15%%35###15%%2%%Duet%%50%%150###16%%8%%Individual%%15%%35###