The PHP similar_text() function


As it's name suggests, the PHP similar_text function tells you how similar two strings of text are. The syntax is:

similar_text( $string1, $string2, $percent )

The first two are the strings you want to compare. The percent tells you how accurate, in percentage terms, the match was. This is optional, though, so you can leave it out. Here's an example that tells the user how accurately they entered a username:

$real_username ="Bill Gates";
$user_attempt = "Bill Bates";

$check = similar_text($real_username, $user_attempt, $percent);

print($check) . "<BR>";
print($percent . "% correct");

The above script will print out the following:

90% correct

The blank space is counted as a character.

<-- Back One Page | Move on to the Next Part -->

Back to the PHP Contents Page