php similar_text() function calculates and compares the similarity of two strings. This article introduces the basic usage method and basic usage examples of php similar_text() function to coders. Interested coders can refer to it.
Definition and usage
similar_text() function calculates the similarity of two strings.
This function can also calculate the percentage similarity of two strings.
Note: levenshtein() function is faster than similar_text() function. However, the similar_text() function provides more accurate results with fewer modifications required.
Syntaxsimilar_text(string1,string2,percent)
Parameters | Description |
---|---|
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 in the two strings. |
PHP version: | 4+ |
Calculate the percentage similarity between two strings:
<?phpsimilar_text("Hello World","Hello Shanghai",$percent);echo $percent. "%";?>
The definition and usage of the php similar_text() function above are all the content shared by the editor. I hope it can give you a reference. I hope everyone will support this site.
The above introduces the definition and usage of the PHP similar_text function, including the content of similar and text functions. I hope it will be helpful to friends who are interested in PHP tutorials.