This article mainly introduces the methods for comparing similar strings in php. the similar_text function in php is used to implement the string similarity comparison function, for more information about how to use php to compare strings, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
The similar_text function of php is used to compare the similarity between two strings.
$ Word2compare = "stupid"; $ words = array ('stupid ', 'Stu and pid', 'hello', 'foobar', 'stpid ', 'upid ', 'stuupid ', 'sstuupiiid',); while (list ($ id, $ str) = each ($ words) {similar_text ($ str, $ word2compare, $ percent ); print "Comparing '$ word2compare' with '$ str':"; print round ($ percent ). "% \ n";}/* Results: Comparing 'stupid 'with 'stupid': 100% Comparing 'stupid 'with 'Stu and pid ': 71% Comparing 'stupid 'with 'Hello': 0% Comparing 'stupid' with 'foobar': 0% Comparing 'stupid 'with 'stpid': 91% Comparing 'stupid 'with 'upid ': 80% Comparing 'stupid 'with 'stuupid': 86% Comparing 'stupid 'with 'sstuupiiid': 71% */
I hope this article will help you with php programming.