similar_text
Calculate the similarity between two strings
similar_text()
function calculates the similarity between 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 precise results with fewer required modifications.
Calculate the similarity of two strings and return the number of matching characters:
<?php echo similar_text ( "Hello World" , "Hello Shanghai" ) ; ?>
Try it yourself
Calculate the percentage similarity between two strings:
<?php similar_text ( "Hello World" , "Hello Shanghai" , $percent ) ; echo $percent . "%" ; ?>
Try it yourself
Similar_text ( string1 , string2 , percent )
parameter | describe |
---|---|
string1 | Required. Specifies the first string to be compared. |
string2 | Required. Specifies the second string to be compared. |
percent | Optional. The name of the variable that specifies the percentage similarity for storage. |