Re: newbie Q: How to say, "if the fileNAME is equal to...", or better yet, "if the fileNAME ends with '.jpg'"?
| From: | Jochem Maas | Date: | Mon, 25 Aug 2008 10:04:35 +0000 |
| Subject: | Re: newbie Q: How to say, "if the fileNAME is equal to...", or better yet, "if the fileNAME ends with '.jpg'"? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278642@lists.php.net to get a copy of this message | ||
Chris schreef:
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.0 can mean false in php:if (stripos(strrev($file), "gpj.") === 0) {== 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?echo $file; }note the ===, 3 equals signs here is very important! check the docs for why.
$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.