Re: Fastest way to find out if a string contains a certain character?

From: Date: Tue, 27 Jul 2010 15:32:55 +0000
Subject: Re: Fastest way to find out if a string contains a certain character?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-307174@lists.php.net to get a copy of this message
Peter Lind wrote: > strstr() returns a string, not a bool > - which would make it slower, though again, not noticeably so (unless, > like Ashley points out, you're doing a HUGE number of strstr() calls). Thanks, both of you. Using strpos saved me 200ms. It wasn't really that I expected to save a lot of time, more that I was interested to know so that I do the right thing in the future, since the meaning of the code is not clearer using one way or the other (i.e. I have to write a comment either way). And yes, I'd already realised using regex was a bad idea :)

« previous php.general (#307174) next »