Re: Fast prefix search?
| From: | Nathan Nobbe | Date: | Sat, 13 Oct 2007 18:53:19 +0000 |
| Subject: | Re: Fast prefix search? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263189@lists.php.net to get a copy of this message | ||
On 10/13/07, Robert Cummings <robert@interjinn.com> wrote:
>
> On Sun, 2007-10-14 at 02:07 +0900, js wrote:
> > On 10/14/07, Nathan Nobbe <quickshiftin@gmail.com> 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.
> }
>
prefix, prefix... hmm. oh, so that means the prefix string has to be at the
front of the haystack!
good catch Rob :)
-nathan