php function makeGoodSite str if substr str http str substr str if sub

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
function makeGoodSite($str)
{
if (substr($str, 0, 7) == "http://")
{
$str = substr($str, 7);
}
if (substr($str, 0, 4) == "www.")
{
$str = substr($str, 4);
}
$answer = "http://www.".$str;
return $answer;
}
function GetFileList($d)
{
$answer = array();
if ($d != '')
{
chdir($d);
}
$dir = opendir (".");
while ($file = readdir ($dir))
{
if (preg_match('/[0-9].TXT/', $file) or preg_match('/[0-9].txt/', $file))
{
$file = substr($file, 0, -4);
array_push ($answer, $file);
}
}
closedir ($dir);
return $answer;
}
function GetTextFileContent($f)
{
$file = './' . $f . '.txt';
$info = [];
$handle = fopen($file, "r");
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
array_push($info, $buffer);
}
$answer = [
'FIO' => $info[1],
'address' => makeGoodSite($info[3]),
'mail' => $info[0],
'Date' => $info[2]
];
return $answer;
}
function showData($input)
{
echo '<tr><td>'. $input['FIO'] .'</td><td>'. $input['mail'] .'</td><td>'. $input['address'] .'</td><td>' .$input['Date'] .'</td></tr>';
}
function printData($input)
{
echo '<table border="0"><tr><td>FIO</td><td>E-Mail</td><td>Web site</td><td>Date</td></tr>';
array_map("showData",$input);
echo '</table>';
}
function together($d)
{
printData(array_map('GetTextFileContent', GetFileList($d)));
}
function comCheck($input)
{
if (substr($input['mail'], -6, -2) == '.com')
{
return true;
}
return false;
}
function comTest($d)
{
$local = array_map('GetTextFileContent', GetFileList($d));
$info = array_filter($local, 'comCheck');
printData($info);
}
function cmp($a, $b)
{
if (strlen($a['mail']) == strlen($b['mail']))
{
return 0;
}
if (strlen($a['mail']) < strlen($b['mail']))
{
return -1;
}
return 1;
}
function sortBymailLength($d)
{
$local = array_map('GetTextFileContent', GetFileList($d));
usort($local, 'cmp');
printData($local);
}
function makeNewArray($d)
{
$local = array_map('GetTextFileContent', GetFileList($d));
$newArray = [];
for ($i=0; $i < count($local); $i += 1)
{
$newArray[$local[$i]['mail']] = $local[$i];
unset($newArray[$local[$i]['mail']]['mail']);
}
}
function comTestAndSort($d)
{
$local = array_map('GetTextFileContent', GetFileList($d));
usort($local, 'cmp');
$info = array_filter($local, 'comCheck');
printData($info);
}
comTestAndSort('123');