Minja
Minja

Reputation: 786

Search array for like terms

I've read in a CSV (Comma Delimited Excel Spreadsheet) file and stored it in multiple arrays (one for each column). When people search for "Deniatus Field Hockey Schedule", they get the search result (which is returned via AJAX). When they search for "Deniatus Hockey", they do not see "Deniatus Field Hockey Schedule" as a netted result.

Is there something like the "like" operator used with MySQL that's available for use with PHP arrays?

Upvotes: 0

Views: 268

Answers (4)

iDsteven
iDsteven

Reputation: 295

preg_match should do the job. You can look for each word in your string and count the number of matches that you get.

If you want to look for words individually, I suggest doing an explode() using " " as your delimiter so that you get an array of individual words to work with.

Upvotes: 0

jeffjenx
jeffjenx

Reputation: 17457

If you are searching for the full phrase Deniatus Hockey, that obviously will not match Deniatus Field Hockey Schedule. You need to break your search string up and search each word individually.

Upvotes: 0

jpiasetz
jpiasetz

Reputation: 1772

Why not just loop over the array and check whether the search string occurs (maybe with stripos)

Upvotes: 1

Sherlock
Sherlock

Reputation: 7597

You can search for strings in strings using stripos.

http://php.net/stripos

You can use it as a callback function looping over all array entries.

Upvotes: 2

Related Questions