So I'm trying to append a string at the end of a row. The row and the string is inputted by the user.
//irrelevant...
$row = $_POST["whichRow"];
$Comment = $_POST["stringValue"];
$lines = array();
$arrayWithComment = array(";", "$actualComment");
$lineCount = 0;
foreach(file('/var/www/html/bkbpNew/tickets.csv') as $line){
if ($lineCount == $row){
array_push($lines, $line, $arrayWithComment[0], $arrayWithComment[1]);}
else{
array_push($lines, $line);}
$lineCount++;
}
file_put_contents('/var/www/html/bkbpNew/tickets.csv', $lines);
And that sort of works, but not in the way that I want it to. Here is the edited file before/after & the desired state:
(Input values for this example are comment = "test" and row = 2)
Desired result of edited file:
1;example;example;example;example;example;example
2;example;example;example;example;example;example;test
3;example;example;example;example;example;example
Edited file BEFORE the above code is executed:
1;example;example;example;example;example;example
2;example;example;example;example;example;example
3;example;example;example;example;example;example
Edited file AFTER the above code is executed:
1;example;example;example;example;example;example
2;example;example;example;example;example;example
;test3;example;example;example;example;example;example
it automatically goes into the next line (Desired result) but I don't want it to. How do I go about this? Cheers!