DOCTYPE html php class FileHandling public static dir public static fu

  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
<!DOCTYPE html>
<?php
class FileHandling {
public static $dir;
public static function SetDir($d){
FileHandling::$dir = $d;
}
public static function GetFileList($filtr) {
$fileNamesArray = glob($filtr);
return $fileNamesArray;
}
public static function GetTextFileContent($file) {
$myfile = fopen($file, "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']);
$resultArray['address'] = str_replace("www.", "", $resultArray['address']);
$resultArray['address'] = "http://www.".$resultArray['address'];
return $resultArray;
}
function __construct() {
}
}
class Person {
private $email;
private $name;
private $date;
private $site;
public function __construct($email, $name, $date, $site) {
$this->email = $email;
$this->date = $date;
$this->name = $name;
$this->site = $site;
}
public function GetName() {
return $this->name;
}
public function GetMail() {
return "<a href=\"mailto:".$this->email."\"".">Отправить e-mail ".$this->name."</a>";
}
public function GetDate() {
$temp = strtotime($this->date);
$temp = date("F d, Y", $temp);
return $temp;
}
public function GetSite() {
return "<a href=\"".$this->site."\"></a>";
}
public function &getPersonData() {
$personArray;
$personArray['FIO'] = $this->name;
$personArray['Site'] = $this->site;
$personArray['mail'] = $this->email;
$personArray['Date'] = $this->date;
return $personArray;
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
FileHandling::SetDir(__DIR__);
$listOfFiles = FileHandling::GetFileList("*.txt");
$file = FileHandling::GetTextFileContent($listOfFiles[0]);
$kurenkov = new Person("vladimir.kurenkov@gmail.com", "Vladimir Kurenkov",
"10.03.2001", "http://www.vk.com");
echo $kurenkov->GetMail()."<br>";
echo $kurenkov->GetName()."<br>";
echo $kurenkov->GetDate()."<br>";
echo $kurenkov->GetSite()."<br>"; //смотри код страницы(!)
$personData = $kurenkov->getPersonData();
echo "<table>";
foreach ($personData as $key => $value) {
echo "<tr><td>".$value."<td></tr>";
}
echo "</table>";
?>
</body>
</html>