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); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.