Re: That crazy IF command!
| From: | Micah Stevens | Date: | Mon, 04 Apr 2005 08:46:40 +0000 |
| Subject: | Re: That crazy IF command! | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39113@lists.php.net to get a copy of this message | ||
Regular expressions are slow. If you need to do some fancy searches, then they
are pretty nice, but if you're just looking for a string in another string,
the stristr() function is faster. (easier to learn too!)
-Micah
On Sunday 03 April 2005 02:48 pm, Josip Dzolonga wrote:
> Matthew Weier O'Phinney wrote:
> > if (strpos($query_holder, "big fat")) {
> > // found
> > }
>
> That's completely wrong. Well try this :
>
> $string = "big fat fatty";
> if (strpos($string, "big fat")) echo 'found';
> else echo 'not found';
>
> It will always return false, because strpos in this case returns 0
> (because the searched text is at position 0) so the IF statement will
> never pass. The corrected version of the code above :
>
> if (strpos($string, "big fat")!==false) echo 'found';
> else echo 'not found';
>
> Regular Expressions are always a better and more elegant solution so
> take a look at www.php.net/preg
>
> These were my 0,02$
>
> --
> Josip Dzolonga
> http://josip.dotgeek.org
>
> jdzolonga[at]gmail.com