I am looking for help to write an efficient PHP algorithm to help me find occurances of a String within another string. Here is currently the situation.
I have two arrays. The first array is the array with text that needs searched (haystack). The second array is an array of terms ot find (needle).
I know that my first array has at least one of my terms from the needles. So, the algorithm needs to say ‘is array2[0] found inside array1[0]? if not, loop, is array2[1] found inside array1[0], etc’ If it is found, exit, advance array1[1] pointer and repeat the process.
I want to make sure this is efficient as I have 10s of 1000s of entries to pricess, and my needle array has 1100 individual needles.
Ok, let’s start with this algorithm, it might not be the fastest but the result is what you want. (Keep loping UNTIL you found the first match)
?>
//EDIT: I commented the hard coded array, creating it now dynamically an added a timer.
It takes about 1 second max, if there is no match.