
similar_text()
(PHP 4, PHP 5)
int similar_text ( string $first , string $second [, float &$percent ] )
Similar_text — calculates the similarity between two strings as described in Oliver [1993]. Note that this implementation does not use a stack as in Oliver's pseudo code, but recursive calls which may or may not speed up the whole process. Note also that the complexity of this algorithm is O(N**3) where N is the length of the longest string.
Let's look code below:
<?php
require('conn.php');
$sql="select title from content order by id desc limit 20"; //calculates the similarity
$result=mysql_query($sql,$conn);
$cf=0;
while($row=mysql_fetch_array($result)){
similar_text($row['title'], $title, $percent); //save as $percent
if($percent>90){$cf=1;break;} //Tuoboo.com: compare the similarity
}
if($cf==1){
echo "<SCRIPT language=JavaScript>alert('Sorry, you are forbidden.');";
echo "this.location.href='vbscript:history.back()';</SCRIPT>";
mysql_close();
exit();
}
?>
This code is useful where the title field to expand into other fields, such as content field, and the PHP functions are too powerful.
