-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimilarNames.php
49 lines (49 loc) · 1.48 KB
/
SimilarNames.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
<!DOCTYPE html>
<html>
<head>
<title>Similar Names</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<?php include 'includes/inc_header.php'; ?>
<h1>Similar Names</h1><hr />
<?php
$SignNames = array(
"Rat",
"Ox",
"Tiger",
"Rabbit",
"Dragon",
"Snake",
"Horse",
"Goat",
"Monkey",
"Rooster",
"Dog",
"Pig");
$LevenshteinSmallest = 999999;
$SimilarTextLargest = 0;
for ($i=0; $i<11; ++$i) {
for ($j=$i+1; $j<12; ++$j) {
$LevenshteinValue = levenshtein($SignNames[$i], $SignNames[$j]);
if ($LevenshteinValue < $LevenshteinSmallest) {
$LevenshteinSmallest = $LevenshteinValue;
$LevenshteinWord1 = $SignNames[$i];
$LevenshteinWord2 = $SignNames[$j];
}
$SimilarTextValue = similar_text($SignNames[$i], $SignNames[$j]);
if ($SimilarTextValue > $SimilarTextLargest) {
$SimilarTextLargest = $SimilarTextValue;
$SimilarTextWord1 = $SignNames[$i];
$SimilarTextWord2 = $SignNames[$j];
}
}
}
echo "<p>The levenshtein() function has determined that "$LevenshteinWord1" and "$LevenshteinWord2" are the most similar names.</p>\n";
echo "<p>The similar_text() function has determined that "$SimilarTextWord1" and "$SimilarTextWord2" are the most similar names.</p>\n";
?>
<?php include 'includes/inc_footer.php'; ?>
</div>
</body>
</html>