virtually_equal() | perhaps_virtually_equal() | ||
---|---|---|---|
"Water" | "Forest" | false | false |
"Forest" | "Fire storm" | true | true |
"Fire storm" | "Friend" | false | true |
"Friend" | "Enemy" | false | false |
"Enemy" | "Emine'" | true | true |
"Emine'" | "Bird" | false | false |
"Bird" | "Breakfast" | false | true |
"Breakfast" | "Barkeeper" | true | true |
"Barkeeper" | "Barchair" | false | true |
"Barchair" | "Bar" | false | true |
"Bar" | "Broarh" | false | true |
"Broarh" | "End" | false | false |
"End" | "Ey maat!" | true | true |
"Ey maat!" | "Sux" | false | false |
"Sux" | "Socks" | true | true |
Idea: Klaus Quindt, Realization: Thiemo Mättig, 2003-12-03
<html>
<head>
<title>PHP Lingual Comparison Operators</title>
<style type="text/css">
body { font-family: Georgia, serif; }
td { border-top: 1px solid #CCCCCC; padding: 2px 20px 1px 0; }
em { color: #669900; }
a { color: #006600; }
#source { background-color: #F7F7F7; }
</style>
</head>
<body>
<h1>PHP Lingual Comparison Operators</h1>
<table>
<tr>
<th></th>
<th></th>
<th>virtually_equal()</th>
<th>perhaps_virtually_equal()</th>
</tr>
<?php
function virtually_equal($a, $b)
{
return soundex($a) == soundex($b);
}
function virtually_not_equal($a, $b)
{
return !virtually_equal($a, $b);
}
function perhaps_virtually_equal($a, $b)
{
return substr(soundex($a), 0, 2) == substr(soundex($b), 0, 2);
}
function perhaps_virtually_not_equal($a, $b)
{
return !perhaps_virtually_equal($a, $b);
}
$tests = array("Water", "Forest", "Fire storm", "Friend", "Enemy", "Emine'",
"Bird", "Breakfast", "Barkeeper", "Barchair", "Bar", "Broarh", "End",
"Ey maat!", "Sux", "Socks");
for ($i = 0; $i < count($tests) - 1; $i++)
{
$a = $tests[$i];
$b = $tests[$i + 1];
echo '<tr>';
echo '<td>"' . htmlspecialchars($a) . '"</td>';
echo '<td>"' . htmlspecialchars($b) . '"</td>';
echo '<td>' . (virtually_equal($a, $b) ? "<em>true</em>" : "false") . '</td>';
echo '<td>' . (perhaps_virtually_equal($a, $b) ? "<em>true</em>" : "false") . '</td>';
echo '</tr>';
}
?>
</table>
<p>
Idea: Klaus Quindt,
Realization: <a href="http://maettig.com/">Thiemo Mättig</a>,
2003-12-03
</p>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?source=1">Show source</a></p>
<div id="source"><?php if (isset($_REQUEST['source'])) show_source(__FILE__); ?></div>
</body>
</html>