Calculate the similarity of two strings and return the number of matching characters:
<?phpecho similar_text("Hello World","Hello Peter");?>The similar_text() function calculates the similarity of two strings.
This function can also calculate the percentage similarity of two strings.
Note: The levenshtein() function is faster than the similar_text() function. However, the similar_text() function provides more accurate results with fewer modifications required.
similar_text( string1,string2,percent )
parameter | describe |
---|---|
string1 | Required. Specifies the first string to compare. |
string2 | Required. Specifies the second string to be compared. |
percent | Optional. Specifies the variable name used to store percent similarity. |
Return value: | Returns the number of matching characters between two strings. |
---|---|
PHP version: | 4+ |
Calculate the percent similarity of two strings:
<?phpsimilar_text("Hello World","Hello Peter",$percent);echo $percent;?>