I'm checking to see if any of the needles /cgi-bin /css etc
are in the haystack $dir
.
In order to check on multiple needles, I have to write the ||
after each strpos()
.
I've seen some other threads on here, but none that really showed the most simplest code.
I'm under the impression that as far as simplicity and minimized code, this is the best way to go about comparing a low quantity (10 or less) of multiple needles to the haystack with strpos.
If you know of a shorter and more preferred way to do this please leave an answer below.
But no extra complicated code. An array would be fine, but keep it simple and short.
Code:
if (strpos($dir, '/cgi-bin') || strpos($dir, '/css') || strpos($dir, '/images') || strpos($dir, '/includes') || strpos($dir, '/test') !== false)
continue;
Use a regular expression:
if (preg_match('#/(?:cgi-bin|css|images|includes|test)#', $dir)) {
continue;
}