Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP similar_text() Function

PHP similar_text() Function

PHP String Reference Manual PHP String Reference Manual

Example

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

Run Example »


Definition and Usage

The similar_text() function calculates the similarity of two strings.

This function can also calculate the percentage similarity of two strings.

Note:levenshtein() The levenshtein() function is faster than the similar_text() function. However, the similar_text() function provides more accurate results with fewer required modifications.


Syntax

similar_text(

string1,string2,percent

)

Parameters Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.
percent Optional. Specifies the variable name for storing the percentage similarity.

Technical Details

Return Value: Returns the number of matching characters of the two strings.
PHP Version: 4+

More examples

Example 1

Calculate the percentage similarity of two strings:

Run Example »


PHP String Reference Manual PHP String Reference Manual