Размер файла: 2.24Kb
<?php
include "conf.php";
$a = "1";
while ($a < "8") {
if ($a == "1") $cpat = "internet/";
if ($a == "2") $cpat = "computer/";
if ($a == "3") $cpat = "culture/";
if ($a == "4") $cpat = "lichnoe/";
if ($a == "5") $cpat = "smi/";
if ($a == "6") $cpat = "dosug/";
if ($a == "7") $cpat = "sport/";
$infile = $cpat;
$infile .= "index.txt";
$outfile = $cpat;
$outfile .= "sort.txt";
$ifile = fopen ($infile, "r");
$ofile = fopen ($outfile, "w");
while (!feof ($ifile)) {
$cfnf = $cpat;
$cftf = fgets ($ifile, 1024);
$cftf = trim($cftf);
$cfnf .= $cftf;
if ($cftf != "") {
$cfnf .= ".txt";
$fopf = fopen ($cfnf, "r");
$ahf = fgets ($fopf, 1024);
$thf = fgets ($fopf, 1024);
$thf = trim($thf);
$fnf = $cftf;
fclose ($fopf);
$cfns = $cpat;
$cfts = trim(fgets ($ifile, 1024));
$cfns .= $cfts;
if ($cfts != "") {
$cfns .= ".txt";
$fops = fopen ($cfns, "r");
$ahs = fgets ($fops, 1024);
$ths = fgets ($fops, 1024);
$ths = trim($ths);
$fns = $cfts;
fclose ($fops);
if ($ths > $thf) {
fputs ($ofile, "$fns\n");
} else {
fputs ($ofile, "$fnf\n");
$thf = $ths;
$fnf = $fns;
}
}
fputs ($ofile, "$fnf\n");
$thf = $ths;
$fnf = $fns;
}
}
fclose ($ifile);
fclose ($ofile);
$ifile = fopen ($outfile, "r");
$ofile = fopen ($infile, "w");
$tem = fgets ($ifile, 1024);
fputs ($ofile, "$tem");
while (!feof ($ifile)) {
$cfnf = $cpat;
$cftf = trim (fgets ($ifile, 1024));
$cfnf .= $cftf;
if ($cftf != "") {
$cfnf .= ".txt";
$fopf = fopen ($cfnf, "r");
$ahf = fgets ($fopf, 1024);
$thf = fgets ($fopf, 1024);
$fnf = $cftf;
fclose ($fopf);
$cfns = $cpat;
$cfts = trim(fgets ($ifile, 1024));
$cfns .= $cfts;
if ($cfts != "") {
$cfns .= ".txt";
$fops = fopen ($cfns, "r");
$ahs = fgets ($fops, 1024);
$ths = fgets ($fops, 1024);
$fns = $cfts;
fclose ($fops);
if (trim($ths) > trim($thf)) {
fputs ($ofile, "$fns\n");
} else {
fputs ($ofile, "$fnf\n");
$thf = $ths;
$fnf = $fns;
}
}
fputs ($ofile, "$fnf\n");
$thf = $ths;
$fnf = $fns;
}
}
fclose ($ifile);
fclose ($ofile);
unlink ($outfile);
$a++;
}
?>