ok well this is how i have been doing things for a long time for updating and i would just replace with an empty array to delete but i would have to re-write the whole file...
$poll_lines = file($poll_log);
$total_lines = count($poll_lines);
##### #####
##### Checks if voted, if did then adds vote #####
if($poll_action == "Vote" && !empty($poll_answer))
{
$flag = 0;
for($i=1; $i < $total_lines && flag; $i++)
{
$poll_array = explode("|::|", $poll_lines[$i]);
##### Sees if this rows the right one, if so adds a vote #####
if($poll_array[0] == $poll_answer)
{
$before = "$poll_array[0]|::|$poll_array[1]|::|$poll_array[2]|::|";
$poll_array[2]++;
$after = "$poll_array[0]|::|$poll_array[1]|::|$poll_array[2]|::|";
$fp = fopen($poll_log, "r");
flock($fp,2);
$poll_content = fread($fp, filesize($poll_log));
fclose($fp);
$after = str_replace("$before","$after", $poll_content);
$fp = fopen($poll_log, "w");
flock($fp,2);
fwrite($fp, $after);
fclose($fp);
$flag = 1;
##### reads file again with newest votes #####
$poll_lines = file($poll_log);
}
}
}
ok well this does work however i'm wondering if there's a way to just go and update the ONE part of the file i want without having to re-write the whole thing... or is it possoble to do this reading/writing/updating (i know you can open with "a" and fwrite a record to just the end of a file but how can i do this in the middle to replace an old record?) all in one fopen? and i'm wondering if i'm doing flock right...
lots of questions heh, just hard to really get it so i understand it... anyone that can show me a good faster way to update/delete records in a text file please tell me... =)
or tell me that my way is fine because it seems a little scetchy to me =/
thanks =)
the more anyone can tell me the better... just looking for the best way to do this before i start fixing up all my old 2 y/o scripts and there old messy code...
~Blake
PS also i been learning C recently and wondering if you could make strutures like you can in C in PHP some how?