diff --git a/Information.txt b/Information.txt index ee219b5..443cd79 100644 --- a/Information.txt +++ b/Information.txt @@ -5,7 +5,3 @@ Зайцева;Анжела;Игоревна;1998-12-12;Женжина;+7;4444444444;aksjfhfka@mail.ru; Петров;Петр;Петрович;1987-03-02;Мужчина;+7;7777777777;jksghhsdkj@gmail.com; Зайцев;Федор;Александрович;2014-12-22;Мужчина;+7;6667774441;asert@mail.ru; -Билай;Станислав;Романович;1111-11-11;Мужчина;+7;9493761924;stasbilay02@yandex.ru; -Плешкова;Анастасия;Денисовна;1111-11-11;Мужчина;+7;3333333333;ple.anastasiya@gmail.com; -Зайцев;Федор;Александрович;1234-12-12;Мужчина;+7;6667774441;asert@mail.ru; -Билай;Станислав;Романович;1111-11-11;Мужчина;+38;9493761924;stasbilay02@yandex.ru diff --git a/info.php b/info.php index 632db8a..144a635 100644 --- a/info.php +++ b/info.php @@ -20,4 +20,10 @@ $file = fopen($fileName, $fileModeOpen); fwrite($file, $string); fclose($file); +$file = file($fileName); +$str = new Information(); +$res = $str->search($file, "Зайцев"); + +echo $res; + require "table.php"; \ No newline at end of file diff --git a/src/Information.php b/src/Information.php index 65d1aa5..cc8e570 100644 --- a/src/Information.php +++ b/src/Information.php @@ -9,6 +9,7 @@ * @property string $countryCode * @property string $phoneNumber * @property string $email + * @property string $tempString */ class Information { @@ -20,8 +21,7 @@ class Information public string $countryCode; public string $phoneNumber; public string $email; - - //public $gender; + public string $tempString; public function __construct() @@ -66,12 +66,26 @@ class Information public function toString(): string { return $this->surname . ';' . $this->name . ';' . $this->patronymic . ';' . $this->dateOfBirth . ';' . - $this->gender . ';' . $this->countryCode . ';' . $this->phoneNumber . ';' . $this->email . "\n"; + $this->gender . ';' . $this->countryCode . ';' . $this->phoneNumber . ';' . $this->email . ";\n"; } - public function search() + /** + * @param array $textArrayFromFile + * @param string $search + * @return string|null + */ + public function search(array $textArrayFromFile, string $search): ?string { + if($textArrayFromFile) { + foreach ($textArrayFromFile as $str) { + if (str_contains($str, $search)) { + $this->tempString = strstr($str, $search); + return substr($this->tempString, 0, strlen($search)); + } + } + } + return null; } }