Easy Tutorial
❮ Func Math Mt Srand Func Math Sinh ❯

PHP similar_text() Function

PHP String Reference Manual

Example

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


Definition and Usage

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

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

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


Syntax

Parameter Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.
percent Optional. Specifies the variable name to store the percentage similarity.

Technical Details

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

More Examples

Example 1

Calculate the percentage similarity between two strings:


❮ Func Math Mt Srand Func Math Sinh ❯