My PHP script needs to check for matches throughout an array of data. It’s currently looking for exact string matches. I’d like it to be less strict.
For example, if the array holds the string “Tom and Jerry” I would like to return true for: “Tom Jerry”, “Tom & Jerry” and maybe even “Tom and Jery”. I found links to PHP search engines they are more complex and not really what I need. My data is fairly small and dynamic, so there’s no indexing.
I know I could write a big hairy regular expression, but I’m pretty sure I would be reinventing the wheel, because I’m sure others have already done this. Any advice on where to look or how to approach this would be much appreciated.
EDIT: To clarify, I’m trying to avoid entering all the dynamically generated data into a DB.
I just discovered two functions which appear to do what I want:
similar_text()levenshtein()Both seem to return an intiger representing the "closeness" of the match between two strings. The difference between the two is over my head.
My search was aided by this S.O. question.