Keep in mind, however, that if you use strpos(), you have to invoke the function multiple times, once for each character that constitutes whitespace: space, tab, newline, return, formfeed.
m98marba
What kind of overhead do you refer to? I see no mention of overhead in the PHP documentation. The only thing I see refered to in connection with strpos() is strstr() which is more memory intensive.
Please share your knowledge.
Thanks.
DRJ478
I havn't done any benchmarking to compare strpos() and preg_match() myself. And I don't know exactly how the (quite sofisticated) matching machinery is coded.
But, simply speaking, because preg_match() is made to handle such a variety of patterns (see
you may realize that it will in most cases take more CPU-power compared to, i.e., a function like strpos(). The only thing strpos($haystack, $needle) do is finding the first occurance of $needle in $haystack so it is actually designed for that particular task so it should be faster. Moreover, I think it's mentioned somewhere in the manual (not sure can't find it) and that what I learnd myself from other programmers.
With overhead I just meant "machinery" to handle the regular expression patterns. Sorry if I was a bit unclear.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.