Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Are you really using complicated regular expressions inside preg_match or just searching for a substring? – galymzhan Apr 1 '12 at 8:23
16,000 entries could easily be loaded into notepad++ and you can run simple searches and regular expression searches. Why code? You could even write a macro do that automatically. – NoChance Apr 1 '12 at 8:56
Just searching for a substring, and no I cannot use a desktop based program as our account managers (IT noobs) need to be able to search. – hozza Apr 2 '12 at 18:59
On a side note, is there a better method for using complicated regular expressions? - as I do this also. – hozza Apr 2 '12 at 19:11
up vote 1 down vote accepted

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.

share|improve this answer
I cannot use in_array() or array_search() as they require an exact match. Third option is what im after! Thanks. – hozza Apr 2 '12 at 19:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.