<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
table, td, tr {
border: 1px solid black;
border-collapse: collapse;
}
td, tr{
padding: 5px;
}
</style>
</head>
<body>
<?php
// компаратор по email
function CompareMail($a, $b){
if (strlen($a['mail']) > strlen($b['mail']))
return 1;
else
return 0;
}
// компаратор по email ключа ассоциативного массива
function CompareMailArray($a,$b){
if (strlen(key($a)) > strlen(key($b)))
return 1;
else
return 0;
}
// компаратор по дате регистрации
function CompareByDate($a, $b){
if (strtotime($a['Date']) > strtotime($b['Date']))
return 1;
else
return 0;
}
// проверка на принадлежность к зоне .com
function CheckIfCom($a){
if(strpos($a['mail'], '.com') !== false)
return true;
else
return false;
}
// своя функция для вывода вектора векторов, внешний вектор numeric
function DataOutput($array){
$string = "<table>";
for($i = 0; $i < count($array); $i++)
{
$string = $string."<tr>";
$string = $string."<td>".$array[$i]["mail"]."</td>";
$string = $string."<td>".$array[$i]["FIO"]."</td>";
$string = $string."<td>".$array[$i]["Date"]."</td>";
$string = $string."<td>".$array[$i]["address"]."</td>";
$string = $string."</tr>";
}
$string = $string."</table>";
echo $string;
}
// функция для array_map
function DataOutputAM($foo){
return "<td>".$foo."</td>";
}
// возвращает массив с файлами указанной директории
function GetFileList(){
$iterator = glob("*.txt");
return $iterator;
}
// работа с файлами
function GetTextFileContent($f){
$myfile = fopen($f, "r") or die ("Unable to open file!");
$resultArray;
$resultArray['mail'] = fgets($myfile);
$resultArray['FIO'] = fgets($myfile);
$resultArray['Date'] = strtotime(fgets($myfile));
$resultArray['Date'] = date("d-m-Y",$resultArray['Date']);
$resultArray['address'] = fgets($myfile);
fclose($myfile);
$resultArray['address'] = str_replace("http://", "", $resultArray['address']);
//var_dump($resultArray['mail']);
$resultArray['address'] = str_replace("www.", "", $resultArray['address']);
$resultArray['address'] = "http://www.".$resultArray['address'];
return $resultArray;
}
$fileList = GetFileList();
$users;
$i = 0;
foreach ($fileList as $key => $value) {
$users[$i] = GetTextFileContent($value);
$i++;
}
echo "<table>";
for ($i = 0; $i < count($users); $i++)
{
echo "<tr>";
$bar = array_map('DataOutputAM', $users[$i]);
foreach ($bar as $key => $value) {
echo $value;
}
echo "</tr>";
}
echo "</table><br>";
usort($users, 'CompareMail');
DataOutput($users);
echo "<br>";
$bycom = array_filter($users, 'CheckIfCom');
$bycom = array_values($bycom);
echo "<table>";
for ($i = 0; $i < count($bycom); $i++)
{
echo "<tr>";
$bar = array_map('DataOutputAM', $bycom[$i]);
foreach ($bar as $key => $value) {
echo $value;
}
echo "</tr>";
}
echo "</table><br>";
$arrayByMail;
for ($i = 0; $i < count($users); $i++) {
$arrayByMail[$users[$i]['mail']] = $users[$i];
unset($arrayByMail[$users[$i]['mail']]['mail']);
}
echo "<table>";
foreach ($arrayByMail as $key => $value)
{
echo "<tr>";
foreach ($arrayByMail[$key] as $key1 => $value1) {
echo "<td>".$value1."</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<table><br>";
$outputMail;
foreach ($arrayByMail as $key => $value) {
if(strpos($key, '.com') == false)
{
$outputMail[$key] = $value;
}
}
usort($outputMail, 'CompareMailArray');
foreach ($outputMail as $key => $value)
{
echo "<tr>";
foreach ($outputMail[$key] as $key1 => $value1) {
echo "<td>".$value1."</td>";
}
echo "</tr>";
}
echo "</table><br>";
usort($arrayByMail, 'CompareByDate');
echo "<table>";
foreach ($arrayByMail as $key => $value)
{
echo "<tr>";
foreach ($arrayByMail[$key] as $key1 => $value1) {
echo "<td>".$value1."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>