Ascending order of text file using php


#1

Hello,
i am ascending order of text file.
for example
i make text file whose name saved.txt
ramzan:12 - 12 - 2018:12
ramzan:15 - 03 - 2018:13
ramzan:12 - 05 - 2018:14
ramzan:12 - 10 - 2018:15
i show result ascending order
result show
ramzan:15 - 03 - 2018:13
ramzan:12 - 05 - 2018:14
ramzan:12 - 10 - 2018:15
ramzan:12 - 12 - 2018:12

how can this


#2

Use file() to read the lines of the file into an array. Use array_map() and a user written call-back function to parse/break each line into an array of appropriate fields. Use usort() and another user written call-back function to sort the data on the appropriate field.


#3

send complete code
thanks advance


#5

We are not a code on demand service. A member has told you what to do. It is now up to you to make an attempt at it.


#6

send complete code

Send payment
Then I can send complete code

:smile:


#7

$file=" saved.txt";
$doc=file_get_contents($file);
$line=explode("\n",$doc);
foreach($line as $newline){
$num = explode(":", $newline);
sort($num);
$sex = $num[1];
$string = str_replace(’ ', ‘’, $sex);
echo “…
”;
echo $string . “
”;
$d1=strtotime($string);
echo $d1 . “
”;
echo date(“d-m-Y”, $d1) . “
”;
}