Under the following conditions, using strpos()
instead of preg_match()
will be faster.
- Not using
matches
variables. - Not using a pattern including pattern modifiers.
- Not using a pattern including meta characters.
<?php
if (preg_match("/abc/", $var)) { // UnneededRegularExpression: Using `strpos()` instead of `preg_match()` will be faster.
something($var);
}
<?php
if (strpos($var, "abc") !== false) {
something($var);
}