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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2010-07-27 at 09:30 +0200, Gary wrote:

> I know there are a number of possible ways of doing this, but I was just
> wondering if there is an accepted way of doing so which is better
> than others, performance wise. An idiom, if you like.
> 
> 


If you only need to find if a string contains the character and not its
position, then strstr() (or strchr(), but according to the manual they
are both the same) is the fastest route to go down. Using strpos() is
slower because it has to return the actual position of what you were
looking for, and a regex will be the slowest of all (and one would have
to question the sanity of someone using a regex to find a single
character in a string!)

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux