I just want to known which one will be fast of strpos()/stripos() or preg_match() functions in php.
Benchmarking is a tricky business, but it's fairly safe to say that preg_match
is slower than strpos
or stripos
. This is because the PRCE functions implement a REGEX engine that is much more powerful and flexible than the string functions.
They also do different things. strpos
will tell you the index of the start of the string inside another string, whereas preg_match
is mainly used to probe the format of a string, and to retrieve sections of it based on regular expressions.
In short, if you simply want to find a string inside another string, use strpos
or stripos
.