rss

Apr
23

PHP: Fuzzy Address Matching Algo (Levenshtein)

Posted (Amit) in MySQL, PHP on 23-04-2010

Few days back i encountered a weird problem.
I had three tables in my DB viz: students, sites, company. Student table has the address fields and a column named “site_id” to connect it to the sites table. Sites table also has its address fields.

Now the challenge was to update the “site_id” field of the students table based on the matching address in the student and the site table. The address fields in both the tables were divided into following fields

  • address1
  • address2
  • city
  • state
  • country
  • zip

Now i had to think of a solution of how to do it. After googling a while i found a function called “levenshtein()” in PHP. This function calculated the distance between two given strings, bingo i got an idea and implemented the sddress matching algorithm. I have attached the file with this post.
Kindly let me if that was helpful to you.

Download the code from here -> fuzzy-match

Share

Post a comment



Amit Yadav is Stephen Fry proof thanks to caching by WP Super Cache