-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagram1.php
83 lines (64 loc) · 1.18 KB
/
anagram1.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
<html>
<?php
function my_in_array( $string,$frequency)
{
foreach($frequency as $eachElement)
{
if($string==$eachElement)
{
return true;
}
}
return false;
}
if(isset($_GET["string1"])&&($_GET["string2"]))
{
$string1 = $_GET['string1'];
$string2 = $_GET['string2'];
$length1 = strlen($string1);
$length2 = strlen($string2);
$arr=array();
if($length1==$length2)
{
for($i=0;$i<$length1;$i++)
{
for($j=0;$j<$length2;$j++)
{
if($string1[$i]==$string2[$j])
{
if(my_in_array($j,$arr))
{
continue;
}
else
{
array_push($arr,$j);
}
if($i==$length1-1)
{
echo "true";
}
break;
}
}
if($j==$length2)
{
echo "false";
break;
}
}
}
else
{
echo "This is not anagram";
}
}
?>
<body>
<form action ="anagram1.php" method ="get">
First string:<input type="text" name ="string1"/><br>
Second string:<input type="text" name="string2"/><br>
<button type="submit" name="submit">click here</button>
</form>
</body>
</html>