Re: Fast prefix search?

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

 



On Sun, 2007-10-14 at 02:07 +0900, js wrote:
> On 10/14/07, Nathan Nobbe <quickshiftin@xxxxxxxxx> wrote:
> > can you use the php string manipulation functions ?
> 
> I'll probably use strstr() to check whether a string starts with some prefix.

>From the help for PHP's strstr() function:

    "Note: If you only want to determine if a particular
     needle occurs within haystack, use the faster and
     less memory intensive function strpos() instead."

So don't use strstr() use strpos(). Specifically use it like follows:

    if( strpos( $haystack, $prefix ) === 0 )
    {
        // it's a prefix.
    }

This wasn't particularly meant to address the original question, only
the improper use of strstr() for checking if one string exists within
another.

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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