Efficient Filtering of Large Arrays in PHP – Alternatives to preg_match()

arrayPHPsearch

I have a log that our web application builds. Each month it contains around 16,000 entries of a string with about the average sentence worth of text.

To filter/search through these in our admin panel the script uses preg_match() but this seems to be taking ages and timing out on the 30sec limit. I have isolated that it is indeed the preg_match() that causes the time out.

Is there a more efficient way to search through values in a large array for a users input?

Best Answer

I would research in_array() and array_search() to see if they catch what you're looking for. Otherwise, use a for loop and use stripos() on each entry's text, which is my normal tool for searching in strings.

Related Topic