Re: That crazy IF command!

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

 



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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux