From 8d9454e1a71003670bd2af492f9f44be72e7604f Mon Sep 17 00:00:00 2001 From: Nevsen Date: Wed, 23 Sep 2020 02:44:38 +0300 Subject: [PATCH 1/3] first lesson --- date.php | 7 +++++++ index.php | 29 +++++++++++++++++++++++++++++ template.html | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 date.php create mode 100644 index.php create mode 100644 template.html diff --git a/date.php b/date.php new file mode 100644 index 0000000..18f3c18 --- /dev/null +++ b/date.php @@ -0,0 +1,7 @@ +Time: $time
Date: $date"; +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..7f7f15b --- /dev/null +++ b/index.php @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/template.html b/template.html new file mode 100644 index 0000000..4f58772 --- /dev/null +++ b/template.html @@ -0,0 +1,22 @@ + + + + + + + +

{{ h1 }}

+Краткая биография обо мне +Родился в 1985 году в городе Москва. Закончил в 2008 году МАИ. +На данный момент работаю ведущим инженером в крупной авиакомпании. +Поскольку я люблю авиацию, то хотел бы поделиться несколькими интересными +фотографиями на эту тему +

+Тут можете поместить картинку +

+

+Просто пример жирного текста +

+{{ year }} + + \ No newline at end of file From 7e00b942d6f7b457287a3ae1810480333ef90942 Mon Sep 17 00:00:00 2001 From: Nevsen Date: Mon, 28 Sep 2020 03:02:40 +0300 Subject: [PATCH 2/3] homework for lesson2 --- date.php | 7 ----- index.php | 67 +++++++++++++++++++++++++++++-------------- scripts/task1.php | 12 ++++++++ scripts/task2.php | 41 ++++++++++++++++++++++++++ scripts/task3&4.php | 47 ++++++++++++++++++++++++++++++ scripts/task6.php | 13 +++++++++ scripts/task7.php | 28 ++++++++++++++++++ template.html | 22 -------------- templates/main.php | 65 +++++++++++++++++++++++++++++++++++++++++ templates/task1.php | 21 ++++++++++++++ templates/task2.php | 10 +++++++ templates/task3&4.php | 10 +++++++ templates/task6.php | 9 ++++++ templates/task7.php | 8 ++++++ 14 files changed, 309 insertions(+), 51 deletions(-) delete mode 100644 date.php create mode 100644 scripts/task1.php create mode 100644 scripts/task2.php create mode 100644 scripts/task3&4.php create mode 100644 scripts/task6.php create mode 100644 scripts/task7.php delete mode 100644 template.html create mode 100644 templates/main.php create mode 100644 templates/task1.php create mode 100644 templates/task2.php create mode 100644 templates/task3&4.php create mode 100644 templates/task6.php create mode 100644 templates/task7.php diff --git a/date.php b/date.php deleted file mode 100644 index 18f3c18..0000000 --- a/date.php +++ /dev/null @@ -1,7 +0,0 @@ -Time: $time
Date: $date"; -?> \ No newline at end of file diff --git a/index.php b/index.php index 7f7f15b..401f022 100644 --- a/index.php +++ b/index.php @@ -1,29 +1,52 @@ $value) + { + if (!in_array($value,array(".",".."))) + { + if (is_dir($path . DIRECTORY_SEPARATOR . $value)) + { + $result[$value] = dirToArray($path . DIRECTORY_SEPARATOR . $value); + } + else + { + $result[] = $value; + } + } + } + + return $result; +} + +function renderTemplates($entryPoint){ + $templates = dirToArray($entryPoint); + $content = ''; + + foreach ($templates as $key => $value) { + $content = include("$entryPoint/$value"); + } + return $content; - $content = str_replace("{{ year }}", $template, $content); - echo $content; - - /* task 5 - swap two vars - $a=$a+$b-($b=$a) - */ - - /* task 3 - $a = 5; - $b = '05'; - - var_dump($a == $b); // true потому что производится не строгое сравнение с приведением типа +} - var_dump((int)'00012345'); // Почему 12345? При явном приведении строки в целочисленное число - нули отбрасываются +// function renderTemplatesRecursive($pageName, $content = ''){ +// ob_start(); +// $filename = 'templates/' . $pageName . '.php'; +// if(file_exists($filename)){ +// include($filename); +// } +// return ob_get_clean(); +// } - var_dump((float)123.0 === (int)123.0); // false потому что сравнение строгое со сравнением типов - они разные - var_dump((int)0 === (int)'hello, world'); // true потому что приведение строки к численному типу дает 0 - */ +renderTemplates('templates'); ?> \ No newline at end of file diff --git a/scripts/task1.php b/scripts/task1.php new file mode 100644 index 0000000..d1a11dc --- /dev/null +++ b/scripts/task1.php @@ -0,0 +1,12 @@ + 0) { + $sub = $a - $b; +} elseif ($a && $b < 0) { + $mul = $a * $b; +} else { + $sum = $a + $b; +} +?> \ No newline at end of file diff --git a/scripts/task2.php b/scripts/task2.php new file mode 100644 index 0000000..f5d18fb --- /dev/null +++ b/scripts/task2.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/scripts/task3&4.php b/scripts/task3&4.php new file mode 100644 index 0000000..f10da0c --- /dev/null +++ b/scripts/task3&4.php @@ -0,0 +1,47 @@ + \ No newline at end of file diff --git a/scripts/task6.php b/scripts/task6.php new file mode 100644 index 0000000..eddaccc --- /dev/null +++ b/scripts/task6.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/scripts/task7.php b/scripts/task7.php new file mode 100644 index 0000000..c4122ec --- /dev/null +++ b/scripts/task7.php @@ -0,0 +1,28 @@ + 10 && $str < 20){ //11 - 19 + return $for_5; + } + if ($str_x > 1 && $str_x < 5){ //2,3,4 + return $for_2; + } + if ($str_x == 1){ //1 + return $for_1; + } + return $for_5; +} + +$h = handleCases(getHours(), 'час', 'часа', 'часов'); +$m = handleCases(getMinutes(), 'минута', 'минуты', 'минут'); +?> \ No newline at end of file diff --git a/template.html b/template.html deleted file mode 100644 index 4f58772..0000000 --- a/template.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - -

{{ h1 }}

-Краткая биография обо мне -Родился в 1985 году в городе Москва. Закончил в 2008 году МАИ. -На данный момент работаю ведущим инженером в крупной авиакомпании. -Поскольку я люблю авиацию, то хотел бы поделиться несколькими интересными -фотографиями на эту тему -

-Тут можете поместить картинку -

-

-Просто пример жирного текста -

-{{ year }} - - \ No newline at end of file diff --git a/templates/main.php b/templates/main.php new file mode 100644 index 0000000..80cacf6 --- /dev/null +++ b/templates/main.php @@ -0,0 +1,65 @@ + + + + + Lesson2 + + + +
+ +
+ + \ No newline at end of file diff --git a/templates/task1.php b/templates/task1.php new file mode 100644 index 0000000..c1d008a --- /dev/null +++ b/templates/task1.php @@ -0,0 +1,21 @@ + +
+

Задание 1

+
+
+ A: +
+
+ B: +
+
+ Сумма: +
+
+ Разность: +
+
+ Произведение: +
+
+
\ No newline at end of file diff --git a/templates/task2.php b/templates/task2.php new file mode 100644 index 0000000..f2589f2 --- /dev/null +++ b/templates/task2.php @@ -0,0 +1,10 @@ + +
+

Задание 2

+

Значения чисел от $a до 15

+
+
+ A: +
+
+
\ No newline at end of file diff --git a/templates/task3&4.php b/templates/task3&4.php new file mode 100644 index 0000000..d642dde --- /dev/null +++ b/templates/task3&4.php @@ -0,0 +1,10 @@ + +
+

Задание 3,4

+
+
Сумма:
+
Разность:
+
Произведение:
+
Частное:
+
+
\ No newline at end of file diff --git a/templates/task6.php b/templates/task6.php new file mode 100644 index 0000000..02cd796 --- /dev/null +++ b/templates/task6.php @@ -0,0 +1,9 @@ + +
+

Задание 6

+
+
Число:
+
Степень:
+
Значение:
+
+
\ No newline at end of file diff --git a/templates/task7.php b/templates/task7.php new file mode 100644 index 0000000..08cae9c --- /dev/null +++ b/templates/task7.php @@ -0,0 +1,8 @@ + + +
+

Задание 7

+
+
Текущее время:
+
+
\ No newline at end of file From cc4924150db3be174ba94a55677dcb1e7e7452ee Mon Sep 17 00:00:00 2001 From: Nevsen Date: Tue, 29 Sep 2020 20:21:27 +0300 Subject: [PATCH 3/3] some updates and refactor --- scripts/task1.php | 4 ++-- scripts/task3&4.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/task1.php b/scripts/task1.php index d1a11dc..fae2e6c 100644 --- a/scripts/task1.php +++ b/scripts/task1.php @@ -2,9 +2,9 @@ $a = rand(-50, 50); $b = rand(-50, 50); -if ($a && $b > 0) { +if ($a >= 0 && $b >= 0) { $sub = $a - $b; -} elseif ($a && $b < 0) { +} elseif ($a < 0 || $b < 0) { $mul = $a * $b; } else { $sum = $a + $b; diff --git a/scripts/task3&4.php b/scripts/task3&4.php index f10da0c..00518da 100644 --- a/scripts/task3&4.php +++ b/scripts/task3&4.php @@ -12,18 +12,14 @@ function mul($arg1, $arg2){ } function div($arg1, $arg2){ - if($arg1 == 0 || $arg2 == 0) { + if($arg2 == 0) { return 'Ошибка! На ноль делить нельзя.'; } return round($arg1 / $arg2, 3); } -function handleData($str){ - return explode(" ", $str); -} - function mathOperation($str){ - $arr = handleData($str); + $arr = explode(" ", $str); switch ($arr[1]) { case '+': return sum($arr[0], $arr[2]); @@ -33,13 +29,17 @@ function mathOperation($str){ return mul($arr[0], $arr[2]); case '/': return div($arr[0], $arr[2]); + default: + return "Нет такой операции"; } } /* Вариант реализации по заданию, выше - собственный function mathOperation($arg1, $arg2, $operation){ - return $operation($arg1, $arg2); + if(function_exists($operation)){ + return $operation($arg1, $arg2); + } } echo mathOperation(4, 7, 'mul');