0

I am looking for a smart algorithm in PHP (vs. the usual built-in PHP functions) to compare 2 strings.. take the following examples:

Whole foods - New York (should equal) Whole Foods Market Tully's Coffee - San Franscisco (should equal) Tully's Coffee

Of course not all source strings are going to be as easy as stripping out the place name. Any interesting algo's out there for something like above? Thanks.

3
  • Should "Whole Foods - New York" also equal "Whole Goods - New York"? In other words, when do you (as a human) consider them equal and when not? Commented Feb 26, 2011 at 5:30
  • @bluesmoon: I believe he simply wants to compare them and see if they're the same store, regardless of the place/city. Commented Feb 26, 2011 at 7:08
  • Possible duplicate of Algorithms for string similarities (better than Levenshtein, and similar_text)? Php, Js Commented Jun 5, 2016 at 0:03

1 Answer 1

2

If you want to compare how similar two strings are, use something like the Levenshtein Distance. (Sometimes used in combination with the Soundex algorithm.)

However, you're going to have to tweak how similar two strings are in order to be considered equal. And the result is unlikely to be considered correct for every case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.