Current Location: Home> Function Categories> similar_text

similar_text

Calculate the similarity between two strings
Name:similar_text
Category:String
Programming Language:php
One-line Description:Calculate the similarity of two strings.

Definition and usage

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.

Example

Example 1

Calculate the similarity of two strings and return the number of matching characters:

 <?php
echo similar_text ( "Hello World" , "Hello Shanghai" ) ;
?>

Try it yourself

Example 2

Calculate the percentage similarity between two strings:

 <?php
similar_text ( "Hello World" , "Hello Shanghai" , $percent ) ;
echo $percent . "%" ;
?>

Try it yourself

grammar

 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.
Similar Functions
Popular Articles