PHP中基于百分比的字符串比较

发布于 2024-08-11 17:22:48 字数 1539 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阿楠 2024-08-18 17:22:48

http://www.php.net/manual/en/function。相似文本.php

similar_text — 计算两个字符串之间的相似度

描述

intimilar_text ( string $first , string $second [, float &$percent ] )

这可以计算两个字符串之间的相似度,如 Oliver 的《编程经典:实现世界最佳算法》(ISBN 0-131-00413-1)中所述。请注意,此实现并不像奥利弗的伪代码中那样使用堆栈,而是使用递归调用,这可能会也可能不会加速整个过程。另请注意,该算法的复杂度为 O(N**3),其中 N 是最长字符串的长度...

正是如此。

http://www.php.net/manual/en/function.similar-text.php

similar_text — Calculate the similarity between two strings

Description

int similar_text ( string $first , string $second [, float &$percent ] )

This calculates the similarity between two strings as described in Programming Classics: Implementing the World's Best Algorithms by Oliver (ISBN 0-131-00413-1). Note that this implementation does not use a stack as in Oliver's pseudo code, but recursive calls which may or may not speed up the whole process. Note also that the complexity of this algorithm is O(N**3) where N is the length of the longest string...

Does exactly that.

时光清浅 2024-08-18 17:22:48

您可以考虑使用 levenshtein相似文本, soundex,或 变音功能。

You might consider using the levenshtein, similar-text, soundex, or metaphone functions.

葬心 2024-08-18 17:22:48
similar_text('apple', 'apple', $percentage);
echo $percentage. // 100

similar_text('apple', 'aple', $percentage);
echo $percentage. // 88.88
similar_text('apple', 'apple', $percentage);
echo $percentage. // 100

similar_text('apple', 'aple', $percentage);
echo $percentage. // 88.88
幸福%小乖 2024-08-18 17:22:48

另外,如果您将这种比较作为从数据库提取数据的一部分进行,则许多数据库引擎都有 SOUNDS LIKE(或 SOUNDEX)实现。在数据库服务器中执行此操作比在 PHP 中执行此操作更快。

Also, if you're doing this comparison as a part of a data extraction from a database, many DB engines have a SOUNDS LIKE (or SOUNDEX) implementation. Doing this in the DB server would be faster than doing it in PHP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文