检查字符串是否x%相等 [英] Check if strings are x% equal

查看:122
本文介绍了检查字符串是否x%相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较三个字符串:

"a text string" //target string
"a kind of similar text string"
"the cow jumps over the moon"

参数,返回与目标x%相似的结果。

And set a percentage parameter that returns the results that are x% similar to the target.

$results = compare($array,$target,80)

$results // Returns an array with str 1,2, because they are at least 80 similar to the target.

此外,是JavaScript或jQuery中类似的函数吗?

Also, is a similar function possible in JavaScript or jQuery?

推荐答案

在PHP中,有一个函数 similar_text 。至于JavaScript,还有 PHP.js项目,它在JavaScript中重新实现PHP函数。他们执行 similar_text 您可以使用。

In PHP, there is the function similar_text. As for JavaScript, there's the PHP.js project, which re-implements PHP functions in JavaScript. They have an implementation of similar_text you can use.

JavaScript实现不支持percent参数。

The JavaScript implementation doesn't support the percent parameter, it seems.

这篇关于检查字符串是否x%相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆