Jump to content

Set files order to depending size of variable


Huijari

Recommended Posts

So here's my code:

I want it to do so if there is variable &number=5& in textfile1.txt and &number=8& in textfile2.txt then it should sort it textfile2 first in array and textfile1 next...

 

			$array = array();
		// Open the local directory 
		$Directory = opendir(".");

		// Read each file name
		while ($filename = readdir($Directory)) {
			// Deconstruct the file name to get the file suffix in lowercase
			$temp = explode(".", $filename);
			$fileSuffix = strtolower(end($temp));
			// Only add to list if it ends in 'txt'
			if ($fileSuffix == "txt") {
			$file = file_get_contents($filename);
                                                                // SOME CODE TO HERE THAT SEARCH VARIABLES FROM TXT FILES AND SORT BY ITS SIZE
                                                                // like there is variable &number=5& in textfile1.txt and &number=7& in textfile2.txt
                                                                // then it should sort it so textfile2.txt is first then textfile1.txt and so on..
                                                                // here below it just adds it in array for the last
			$addfile = pathinfo($filename, PATHINFO_FILENAME);
				array_push($array, "$addfile");
			}
		}

		// Close directory
		closedir($Directory); 

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.