hi i have problem in read/write file:
i need some help:
i have 2 file, 1- result.txt and 2-strings.txt
string is like this
>
I just moved to Germany two months ago and bought an 07 MDX from another military member. It has everything I could want. We just returned from a week driving through the Alps and this SUV is simply amazing. Granted, I get to drive it much faster than I could in the states,
then i need to get words from string.txt then put them on results.txt
so problem is not get words…i have words in array,,,
i put every word in one line of result.txt
but i have to add time of appearing(how many time this word repeated) of every word in this line,,,
if i result.txt if word exist i should update that line with add 1 to time of appering and if not exist i should add this word to one line of this result.txt}
result.txt is some thing like this:
“`
[CODE]yes 2
i 3
Germany 1
returned 2[/CODE]
i wrote below code:
“`
[code=php] while (!feof($file_handle2)) {
$line2=fgets($file_handle2);
$exist=0;
if (strpos($line2, $word ) !== FALSE){
global $exist;
$exist=1;
break;
$words = explode(” “, $line2);
$words[2]++;
fwrite($file_handle2, $word.” “.$words[2].”n”);
}
//when all of the file searched
}if ($exist==0) {
fwrite($file_handle2,$word.” “.1.”.”n”);
}
[/code]
but every time i wana add one line, just first line overwriting,,,i wana add new line when word is not exist before in result.txt , and edit current line when word exist before in result.txt
… i know my code is wrong but how should edit or override this?