You can use the php metaphone () function to generate metaphonic code for each name and save them along with the names.
<?php print "chris" . "\t" . metaphone("chris") . "\n"; print "christian" . "\t" . metaphone("christian") . "\n"; print "christine" . "\t" . metaphone("christine") . "\n";
Then you can use the levenshtein distance algorithm (either in php [http://php.net/manual/en/function.levenshtein.php] or in mysql [http://www.artfulsoftware.com/infotree/queries.php # 552]) to calculate the distance between metacodes. In my test below a distance of 2 or less, it seemed like the level of similarity you are looking for.
<?php $names = array( array('mike',metaphone('mike')), array('chris',metaphone('chris')), array('chrstian',metaphone('christian')), array('christine',metaphone('christine')), array('michelle',metaphone('chris')), array('mick',metaphone('mick')), array('john',metaphone('john')), array('joseph',metaphone('joseph')) ); foreach ($names as $name) { _compare($name); } function _compare($n) { global $names; $name = $n[0]; $meta = $n[1]; foreach ($names as $cname) { printf("The distance between $name and {$cname[0]} is %d\n", levenshtein($meta, $cname[1])); } }
source share