I\'m writing PHP code to parse a string. It needs to be as fast as possible, so are regular expressions the way to go? I have a hunch that PHP string functions are more expe
If what you're doing is at all reasonable to do using string functions, you should use them. Like, if you're determining whether a constant string 'abc'
occurs in $value
, you definitely want to check strpos($value, 'abc') !== false
, not preg_match('/abc/', $value)
. If you find yourself doing a lot of string reshuffling and transformations in order to accomplish what you would've with a regex, though, you're almost certainly going to wind up destroying both performance and maintainability.
When concerned about speed, though, when it comes down to it, don't think about it, clock it. The time
command is your friend.