note 62715 deleted from function.similar-text by googleguy

From: Date: Wed, 16 Jan 2013 05:28:26 +0000
Subject: note 62715 deleted from function.similar-text by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193090@lists.php.net to get a copy of this message
Note Submitter: dmitry dot polushkin at gmail dot com ---- Well... hard to explain, why I have written this function, but maybe it will be usefull. <?php // returns the percentage of the string "similarity" function str_compare($str1, $str2) { $count = 0; $str1 = ereg_replace("[^a-z]", ' ', strtolower($str1)); while(strstr($str1, ' ')) { $str1 = str_replace(' ', ' ', $str1); } $str1 = explode(' ', $str1); $str2 = ereg_replace("[^a-z]", ' ', strtolower($str2)); while(strstr($str2, ' ')) { $str2 = str_replace(' ', ' ', $str2); } $str2 = explode(' ', $str2); if(count($str1)<count($str2)) { $tmp = $str1; $str1 = $str2; $str2 = $tmp; unset($tmp); } for($i=0; $i<count($str1); $i++) { if(in_array($str1[$i], $str2)) { $count++; } } return $count/count($str2)*100; } ?>

« previous php.notes (#193090) next »