-
Notifications
You must be signed in to change notification settings - Fork 1
/
06-ModifyString.php
77 lines (71 loc) · 1.94 KB
/
06-ModifyString.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
<!DOCTYPE html>
<html>
<head>
<title>06. Modify String</title>
</head>
<body>
<form action="" method="GET">
<input type="text" name="string" />
<input type="radio" name="modifier" id="checkPalindrome" value="checkPalindrome" />
<label for="checkPalindrome">Check Palindrome</label>
<input type="radio" name="modifier" id="reverseString" value="reverseString" />
<label for="reverseString">Reverse String</label>
<input type="radio" name="modifier" id="spliter" value="spliter" />
<label for="spliter">Split</label>
<input type="radio" name="modifier" id="hashString" value="hashString" />
<label for="hashString">Hash String</label>
<input type="radio" name="modifier" id="shuffleString" value="shuffleString" />
<label for="shuffleString">Shuffle String</label>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if ($_GET && isset($_GET['submit'])) {
$modifier = $_GET['modifier'];
$string = $_GET['string'];
switch ($modifier) {
case "checkPalindrome":
echo $string . checkPalindrome($string);
break;
case "reverseString":
echo reverseString($string);
break;
case "spliter":
echo spliter($string);
break;
case "hashString":
echo hashString($string);
break;
case "shuffleString":
echo shuffleString($string);
break;
}
}
function checkPalindrome($str) {
$str = strtolower($str);
$reversed = strrev($str);
if ($str == $reversed) {
return " is a palindrom";
} else {
return " is not a palindrom";
}
}
function reverseString($str) {
return strrev($str);
}
function spliter($str) {
$str = trim($str);
$arr = str_split($str);
return implode(" ", $arr);
}
function hashString($str) {
$crypted = crypt($str);
return $crypted;
}
function shuffleString($str) {
$arr = str_split($str);
shuffle($arr);
return implode("", $arr);
}
?>
</body>
</html>