English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String String Functions Manual
The similar_text() function is used to calculate the similarity between two strings.
int similar_text ( string $first , string $second [, float &$percent ] )
Used to calculate the similarity between two strings
Returns the number of matching characters in the two strings.
Number | Parameters and Description |
---|---|
1 | first (required) Information about the first string |
2 | second (required) Information about the second string |
3 | percent (optional) By passing the third parameter by reference, similar_text() will calculate the similarity percentage. |
Try the following example, calculate www.oldtoolbag.com and oldtoolbag.com The similarity is:
<?php //Calculate www.oldtoolbag.com and oldtoolbag.com The similarity echo similar_text("www.oldtoolbag.com,"oldtoolbag.com); ?>Test and See‹/›
Output Result
9
Try the following example, calculate www.oldtoolbag.com and oldtoolbag.com The percentage similarity of these two strings is:
<?php //Calculate www.oldtoolbag.com and oldtoolbag.com This two strings have a percentage similarity of similar_text("www.oldtoolbag.com,"oldtoolbag.com,$percent); echo $percent; ?>Test and See‹/›
Output Result
81.818181818182