Php: similar string method, php string
This article describes how php compares similar strings. 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.