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.

Simbatish
  • 1
  • 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? – bluesmoon Feb 26 '11 at 05:30
  • @bluesmoon: I believe he simply wants to compare them and see if they're the same store, regardless of the place/city. – Ryan McCue Feb 26 '11 at 07:08
  • Possible duplicate of [Algorithms for string similarities (better than Levenshtein, and similar\_text)? Php, Js](http://stackoverflow.com/questions/5351659/algorithms-for-string-similarities-better-than-levenshtein-and-similar-text) – joshweir Jun 05 '16 at 00:03

1 Answers1

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.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466