-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
108 lines (96 loc) · 2.74 KB
/
index.php
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
108
<?php
function drawLine($number) {
return str_repeat('*', $number);
}
function drawStripedLine($number) {
$output = '';
for ($i = 0; $i < $number; $i++) {
$output .= ($i % 2 == 0) ? '*' : '_';
}
return $output;
}
function drawSquare($size) {
$line = str_repeat('*', $size) . PHP_EOL;
return str_repeat($line, $size);
}
function drawParallelogram($number) {
$output = '';
for ($i = 0; $i < $number; $i++) {
$output .= str_repeat('_', $number - $i - 1);
$output .= str_repeat('*', $number);
$output .= str_repeat('_', $i);
$output .= PHP_EOL;
}
return $output;
}
function drawTriangle($number) {
$output = '';
for ($i = 0; $i < $number; $i++) {
$output .= str_repeat('*', $number - $i);
$output .= str_repeat('_', $i);
$output .= PHP_EOL;
}
return $output;
}
function drawRTriangle($number) {
$output = '';
for ($i = 0; $i < $number; $i++) {
$output .= str_repeat('*', $i + 1);
$output .= str_repeat('_', $number - $i - 1);
$output .= PHP_EOL;
}
return $output;
}
$line = $stripedLine = $square = $parallelogram = $triangle = $rtriangle = '';
if (isset($_POST['number'])) {
$number = intval($_POST['number']);
$line = drawLine($number);
$stripedLine = drawStripedLine($number);
$square = drawSquare($number);
$parallelogram = drawParallelogram($number);
$triangle = drawTriangle($number);
$rtriangle = drawRTriangle($number);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Biene Bryle T. Sanico</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="header-container">
<h1>Mobile Dev LAB</h1>
<form action="" method="post">
<input type="number" name="number" placeholder="Enter a number" required>
<input type="submit" value="Submit">
</form>
</div>
<div class="output-container">
<div class="output-box">
<p>The line is:</p>
<?php echo nl2br($line); ?>
</div>
<div class="output-box">
<p>The striped line is:</p>
<?php echo nl2br($stripedLine); ?>
</div>
<div class="output-box">
<p>The square is:</p>
<?php echo nl2br($square); ?>
</div>
<div class="output-box">
<p>The Parallelogram is:</p>
<?php echo nl2br($parallelogram); ?>
</div>
<div class="output-box">
<p>The triangle is:</p>
<?php echo nl2br($triangle); ?>
</div>
<div class="output-box">
<p>The reverse triangle is:</p>
<?php echo nl2br($rtriangle); ?>
</div>
</div>
</body>
</html>