I currently have this block:
if ($type == "up") {
$lines_ = file('../indexIncomplete');
$counter = 0;
foreach ($lines_ as $value) {
$postLen = strlen($post);
if ( substr($value, 0, $postLen) === $post ) {
break;
}
$counter++;
}
list($title, $location, $votes, $poster, $date) = explode("|", $lines_[$counter]);
$votes = $votes + 1;
$newValue = $title.'|'.$location.'|'.$votes.'|'.$poster.'|'.$date;
$lines_[$counter] = $newValue;
file_put_contents('../indexIncomplete', $lines_);
}
This is contained in the HTML page which contains the form which calls it (there is some logic above this block that does validation and stuff, I've narrowed down the problem here).
I'm pulling the contents of a file into an array. Then I look through the array to see if one of them matches $post (a string declared earlier). If it does match, the loop breaks and the counter points to the position in the array that contains the matching string. Then I grab the different parts of the string (using explode()). I grab the $value and increment it and rebuild a new array entry. The I replace the old array entry with the new one I just built on this line:
$lines_[$counter] = $newValue;
I write the new array back to the file. The problem is, the $newValue when being written doesnt seem to pick up any other variable other than $votes, making it look like this:
||1||
Where the number is the correct number of votes. It is supposed to look like this:
$title|$location|$votes|$poster|$date
Also, it doesnt appear on the line it is supposed to. Instead it is appended to the end of the file. I'm very confused.
list($title, ...)line, addprint($lines_[$counter]). Does it contain correct information?===to compare in the if statement.==works though.