Chris schreef:

if (stripos(strrev($file), "gpj.") === 0) {
    echo $file;   }

note the ===, 3 equals signs here is very important! check the docs for why.

== means 'equals', and === means 'is identical to'.
Seems like they would do the same thing when comparing '0' to 'the position in the string where that substr is found'. Why not?

0 can mean false in php:

indeed, php is dynamically typed and happily auto-casts all of the place
without issue ... this can bite you in the ass if your not aware of how
php auto-casts various types, and which types have precendence.

the manual should help, additionally test your assumptions regularly on the 
cmdline
with snippets like:

php -r ' var_dump(("" == false), (1 == "1"), ("two" == 1), ("two" == false));'

using === o test equality force type to be checked as well as 'content' of
the given LH and RH expressions.

$found = 0;
....
if (!$found) {
  echo "File not found";
}

If a substr comparison matches at char 0:

$string = '12345';
$pos = substr($string, '1');

then without the '===' it would give the wrong result as $pos would be converted to false in this example.



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

Reply via email to