Re: That crazy IF command!
| From: | Josip Dzolonga | Date: | Sun, 03 Apr 2005 21:48:44 +0000 |
| Subject: | Re: That crazy IF command! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39110@lists.php.net to get a copy of this message | ||
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