Chamilyan Chamilyan - 1 year ago 105
Javascript Question

Check if strings are x% equal

I want to compare three strings:

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

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.

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

Answer Source

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.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download