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!