-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagram_output.php
52 lines (49 loc) · 1.02 KB
/
anagram_output.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
<?php
echo "You have entered following 2 strings:";
echo "<br>";
echo "String1: ";
echo $string1=$_POST['string1'];
echo "<br>";
echo "String2: ";
echo $string2=$_POST['string2'];
echo "<br>";
echo "<br>";
$output=is_anagram($string1,$string2);
if($output=="")
{
echo "<font color='red'><b>OUTPUT = FALSE";
echo "<br>";
echo "Both Strings Are Not Anagram for Each Other</b></font>";
}
else
{
echo "<font color='green'><b>OUTPUT = TRUE";
echo "<br>";
echo "Both Strings Are Anagram For Each Other</b></font>";
}
function is_anagram($string1,$string2)
{
$status = false;
$string1=strtolower($string1);
$string2=strtolower($string2);
$string1 = str_split($string1);
$string2 = str_split($string2);
sort($string1);
sort($string2);
if($string1 === $string2){
$status = true;
}
return $status;
}
?>
<html>
<body>
<br>
<button onclick="goBack()">Try Again</button>
<script>
function goBack() {
window.history.back();
}
</script>
</body>
</html>