vidyashankara Posted June 20, 2006 Share Posted June 20, 2006 I have a number of text files that are got from the previous page. I need a script to read this files, and make some operations. i have the following script[code]$files = $$HTTP_POST_VARS["files"]; //gets the file names.foreach($files as $file) {$contents=file_get_contents($file); //read contents into an string$atomarray = explode("\n", $atomstart); // read string into arrayfor ($i=0; $i<count($atomarray); $i++) { $resi[$i] = substr($atomarray[$i], 13, 3); // read the 14,15,16 character of each line}$resi = array_unique($resi); //get only unique resultssort($resi); // sort results$resi1 = implode(" ", $resi); //seperate results with a space. if (strpos($resi1, " ABC ")) { $str="Hi" // if ABC exists, $str = "hi"}if (strpos($resi1, "XYZ")) { $str="Bye" // if XYA exists, $str = "bye"} $fp = f open("test.txt", "w");f write ($fp, $str);f close($fp);}[/code]The problem with this script is that when ask it to echo $resi1, It echos only the results from the last file. The script might have to read anywhere between 2 to 5 files, can you find anything wrong with the script?Thanks Link to comment https://forums.phpfreaks.com/topic/12486-php-text-handling/ Share on other sites More sharing options...
zq29 Posted June 20, 2006 Share Posted June 20, 2006 Replace the string mode in fopen() with "a" instead of "w", "w" places the pointer at the begining of the file and truncates the file to 0 length, emptying it. "a" just places the pointer at the end of the file. Link to comment https://forums.phpfreaks.com/topic/12486-php-text-handling/#findComment-47798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.