Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<nav>
<a href="lessons/lesson1.php">урок 1</a>
<a href="lessons/lesson2.php">урок 2</a>
<a href="lessons/lesson3.php">урок 3</a>
</nav>
<p>Всем привет! Добро пожаловать на мой первый сайт.
</p>
Expand Down
19 changes: 19 additions & 0 deletions lessons/classes/StringLib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Utils;

class StringLib
{

private const DEFAULT_CHARSET = 'UTF-8';

public static function mbReverseString(
string $text,
string $encoding = self::DEFAULT_CHARSET
): string {
$convertTextToWin = mb_convert_encoding($text, 'windows-1251', $encoding);
$reverseText = strrev($convertTextToWin);

return mb_convert_encoding($reverseText, $encoding, 'windows-1251');
}
}
19 changes: 13 additions & 6 deletions lessons/classes/TableUtils.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Utils;

class TableUtils
{

Expand All @@ -14,7 +16,8 @@ class TableUtils
4 => 'blue-text'
];

public static function renderTable(bool $styled = false): string {
public static function renderTable(bool $styled = false): string
{
$cells = '';

for ($leftOperand = self::$minOperand; $leftOperand <= self::$maxOperand; $leftOperand++) {
Expand All @@ -24,7 +27,8 @@ public static function renderTable(bool $styled = false): string {
return $cells;
}

private static function getCell(int $leftOperand, bool $styled): string {
private static function getCell(int $leftOperand, bool $styled): string
{
$content = '';

for ($rightOperand = self::$minOperand; $rightOperand <= self::$maxOperand; $rightOperand++) {
Expand All @@ -33,13 +37,14 @@ private static function getCell(int $leftOperand, bool $styled): string {
$result = $leftOperand * $rightOperand;
$resultStyled = $styled ? self::getNumbersStyled($result) : $result;

$string = $leftOperandStyled ." x ". $rightOperandStyled ." = ". $resultStyled;
$string = $leftOperandStyled . " x " . $rightOperandStyled . " = " . $resultStyled;
$content .= self::addBr($string);
}
return $content;
}

private static function addNewRowInTable(int $currentCell, string $content) : string {
private static function addNewRowInTable(int $currentCell, string $content): string
{
return $currentCell == 5 ? $content . '</tr><tr>' : $content;
}

Expand All @@ -53,13 +58,15 @@ private static function addTd(string $text): string
return '<td>' . $text . '</td>';
}

private static function changeColor(int $number): string {
private static function changeColor(int $number): string
{
$class = isset(self::$colors[$number]) ? self::$colors[$number] : 'default-color';

return '<span class="' . $class . '">' . $number . '</span>';
}

private static function getNumbersStyled(int $number): string {
private static function getNumbersStyled(int $number): string
{
$numbersStyled = '';
$stringWithNumbers = strval($number);

Expand Down
30 changes: 30 additions & 0 deletions lessons/handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Beginner level</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../style.css">
</head>
<body>
<p>
<?php

include 'classes/StringLib.php';

use Utils\StringLib;

$result = 'Вы не ввели текст!';
$string = $_POST['string'];

if (isset($string) && !empty($_POST['string'])) {
$text = trim($_POST['string']);
$reverseText = StringLib::mbReverseString($text);
$result = $reverseText;
}

echo $result;
?>
</p>
<a href="lesson3.php">Назад</a>
</body>
</html>
13 changes: 8 additions & 5 deletions lessons/lesson1.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<?php

include 'classes/TableUtils.php';
?>
<!DOCTYPE html>
<html lang="ru">
<head>
Expand All @@ -12,7 +8,14 @@
<body>
<table>
<tr>
<?=TableUtils::renderTable();?>
<?php

include 'classes/TableUtils.php';

use Utils\TableUtils;

echo TableUtils::renderTable();
?>
</tr>
</table>
</body>
Expand Down
13 changes: 8 additions & 5 deletions lessons/lesson2.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<?php

include 'classes/TableUtils.php';
?>
<!DOCTYPE html>
<html lang="ru">
<head>
Expand All @@ -12,7 +8,14 @@
<body>
<table>
<tr>
<?=TableUtils::renderTable(true);?>
<?php

include 'classes/TableUtils.php';

use Utils\TableUtils;

echo TableUtils::renderTable(true);
?>
</tr>
</table>
</body>
Expand Down
21 changes: 21 additions & 0 deletions lessons/lesson3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Beginner level</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../style.css">
</head>
<body>
<form method="POST" action="handler.php">
Введите текст:<br/>
<div class="input-field">
<label>
<input type="text" name="string">
</label>
</div>
<div class="input-field">
<input type="submit" value="Отправить">
</div>
</form>
</body>
</html>
4 changes: 4 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ table {

.yellow-text {
color: yellow;
}

.input-field {
margin: 10px 0 10px 0;
}