1

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?

4
  • 1
    Are you really using complicated regular expressions inside preg_match or just searching for a substring?
    – galymzhan
    Commented Apr 1, 2012 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
    Commented Apr 1, 2012 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
    Commented Apr 2, 2012 at 18:59
  • On a side note, is there a better method for using complicated regular expressions? - as I do this also.
    – hozza
    Commented Apr 2, 2012 at 19:11

1 Answer 1

1

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.

1
  • I cannot use in_array() or array_search() as they require an exact match. Third option is what im after! Thanks.
    – hozza
    Commented Apr 2, 2012 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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