PHP Lingual Comparison Operators

virtually_equal() perhaps_virtually_equal()
"Water""Forest"falsefalse
"Forest""Fire storm"truetrue
"Fire storm""Friend"falsetrue
"Friend""Enemy"falsefalse
"Enemy""Emine'"truetrue
"Emine'""Bird"falsefalse
"Bird""Breakfast"falsetrue
"Breakfast""Barkeeper"truetrue
"Barkeeper""Barchair"falsetrue
"Barchair""Bar"falsetrue
"Bar""Broarh"falsetrue
"Broarh""End"falsefalse
"End""Ey maat!"truetrue
"Ey maat!""Sux"falsefalse
"Sux""Socks"truetrue

Idea: Klaus Quindt, Realization: Thiemo Mättig, 2003-12-03

Show source

<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), 02) == substr(soundex($b), 02);
}

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&auml;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>