-
Notifications
You must be signed in to change notification settings - Fork 1
/
06.StringModifier.php
95 lines (93 loc) · 3.94 KB
/
06.StringModifier.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
<!DOCTYPE html>
<html lang="en">
<head>
<?php header('Content-type: text/html; charset=utf-8'); ?>
<title>String Modifier</title>
</head>
<body>
<main>
<form method="post" action="">
<input type="text" name="inputText">
<label for="palindrome">Check Palindrome</label>
<input type="radio" name="operation" id="palindrome" value="palindrome">
<label for="revString">Reverse String</label>
<input type="radio" name="operation" id="revString" value="revString">
<label for="splitStr">Split</label>
<input type="radio" name="operation" id="splitStr" value="splitStr">
<label for="hashStr">Hast String</label>
<input type="radio" name="operation" id="hashStr" value="hashStr">
<label for="shuffleStr">Shuffle String</label>
<input type="radio" name="operation" id="shuffleStr" value="shuffleStr">
<input type="submit" name="submitter" value="Submit">
</form>
<?php
function isPalindrome($str) {
$tempStr = strtolower(preg_replace("/[^A-Za-z0-9]/", "", $str));
return $tempStr == strrev($tempStr);
}
function reverseString($str) {
$reversedStr = strrev($str);
return $reversedStr;
}
function splitString($str) {
$strToChars = str_split($str);
return $strToChars;
}
function hashString($str) {
$hashedPass = '';
$usedAlgo = '';
if (CRYPT_SHA256 == 1) {
$hashedPass = crypt($str, 'som5eRandomAReallllyRandomStr8ForPass');
$usedAlgo = 'SHA256';
} elseif (CRYPT_BLOWFISH == 1) {
$hashedPass = crypt($str, 'vuehveiurhiwueh4cU');
$usedAlgo = 'Blowfish';
} elseif (CRYPT_STD_DES == 1) {
$hashedPass = crypt($str, 'jb');
$usedAlgo = 'DES Standard';
}
return array($hashedPass, $usedAlgo);
}
function shuffleString($str) {
$shuffledStr = str_shuffle($str);
return $shuffledStr;
}
$inputStr = htmlentities($_POST['inputText']);
$chosenFunc = $_POST['operation'];
if (isset($_POST['submitter']) && strlen(htmlentities($_POST['inputText'])) > 0 && isset($_POST['operation'])) {
switch($chosenFunc) {
case 'palindrome':
if (isPalindrome($inputStr)) {
echo $inputStr . ' is a palindrome!';
} else {
echo $inputStr . ' is not palindrome!';
}
break;
case 'revString':
echo reverseString($inputStr);
break;
case 'splitStr':
$tempArr = splitString($inputStr);
foreach ($tempArr as $charInd => $char) {
echo $char . ' ';
}
break;
case 'hashStr':
echo 'Hashed password: ' . hashString($inputStr)[0] . "<br />" . 'Hashing algorithm: ' . hashString($inputStr)[1];
break;
case 'shuffleStr':
echo shuffleString($inputStr);
break;
default:
}
} elseif (isset($_POST['submitter']) && strlen(htmlentities($_POST['inputText'])) == 0 && isset($_POST['operation'])) {
echo 'Please enter some text!';
} elseif (isset($_POST['submitter']) && strlen(htmlentities($_POST['inputText'])) > 0 && !isset($_POST['operation'])) {
echo 'Please choose an operation!';
} else if (isset($_POST['submitter']) && strlen(htmlentities($_POST['inputText'])) == 0 && !isset($_POST['operation'])) {
echo 'Please enter some text and choose operation!';
}
?>
</main>
</body>
</html>