Jump to content

PHP Text handling...


vidyashankara

Recommended Posts

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 array

for ($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 results
sort($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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.