PHP similar_text () function calculation compares two strings similarity, this article introduces the PHP Similar_text () function Basic use method and the basic use example, the interest code farmer may refer to. Definitions and Usage
The Similar_text () function computes the similarity of two strings.
The function can also calculate the percent similarity of two strings.
Note: the Levenshtein () function is faster than the Similar_text () function. However, the Similar_text () function provides more precise results with fewer required modifications.
Grammar ?
| 1 |
Similar_text (string1,string2,percent) |
| Parameters |
Description |
| String1 |
Necessary. Specify the first string to compare. |
| string2 |
Necessary. Specify the second string to compare. |
| Percent |
Optional. A variable name that sets the percentage similarity for storage. |
Technical details
| return value: |
Returns the number of matching characters for two strings. |
| PHP version: |
4 + |
Instance
Calculates the percentage similarity between two strings:?
| 1 |
<?phpsimilar_text ("Hello World", "Hello Shanghai", $percent); Echo $percent. "%" ;? > |
The above PHP similar_text () function definition and usage is small series to share all the content, hope to give you a reference, also hope that we support the script home.