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
<?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 together($d)
{
$files = getFileList($d);
$answer = [];
array_push($answer,array_map('GetTextFileContent', $files));
var_dump($answer);
}
together('123');