Jump to content

BxK

New Members
  • Posts

    2
  • Joined

  • Last visited

BxK's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thats a step closer, i didn't clarify my question i guess, I'm try to open the contents of the file at: ../i/55b6baa475e85.txt ==> take the first line of file then add it to ==> ../data/top.txt in the order of top 10 posts. the like name is the same as the file name.
  2. I've written an entire system on txt files for posting content, Im trying to take two text files: THE POST | THE NUMBER OF LIKES | | '''''''''''''''|''''''''''''''''' TOP both are in text files. I can get that data into an array as such Array ( [../uploads/likes/55b808022bb92.txt] => 4 [../uploads/likes/55b80982e5573.txt] => 2 [../uploads/likes/55b80d627a030.txt] => 2 [../uploads/likes/55b7e6f02c8b4.txt] => 1 [../uploads/likes/55b815631be8d.txt] => 1 ) and I'm using function top() { if(isset($_GET['top'])) { function readAfterColon($string) { $array = explode(" ",$string, 2); return isset($array[0]) ? $array[0] : ''; } function readLine($lineNumber, $fileName) { $file = file($fileName); return $file[$lineNumber-1]; } function readLineFrom($lineNumber, $fileNames) { $lines = array(); if(is_array($fileNames)) { foreach($fileNames as $fileName) { $lines[$fileName] = readLine($lineNumber, $fileName); } } else { $lines[$fileNames] = readLine($lineNumber, $fileNames); } return $lines; } function getFileNamesFromDirectory($directory = '.') { $fileNames = array(); if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $fileNames[] = $directory . $file; } } closedir($handle); } return $fileNames; } } //include the functions, then: //get the line from every file $descriptions = readLineFrom(1, getFileNamesFromDirectory('../uploads/likes/')); //get the contents arsort($descriptions); foreach($descriptions as $fileName=>$description) { $descriptions[$fileName] = readAfterColon($description); } //display it echo "<pre>\n"; print_r($descriptions); echo "</pre>"; } to get the job done. my question is, whats the easiest way to take those two files and get the top data and show it? Such as the post with 4 likes show as number one ect. Also forgot to add theres three files per post. Data file which has all the posts but just the main post then, the thread file which has all the posts under that, then the post likes file. which are relevant theres one more for ips but thats for likes. I have an idea of how to do the job but i feel as if its just insanely too much, plus, I write code a lot. I've been looking for a new community to join thats welcoming . I use to be apart of a php community before this that got shut down so, hi all! and thanks for any ideas before hand!
×
×
  • 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.