Re: newbie Q: How to say, "if the fileNAME is equal to...", or better yet, "if the fileNAME ends with '.jpg'"?

From: Date: Mon, 25 Aug 2008 00:10:33 +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  Groups: php.general 
Request: Send a blank email to php-general+get-278616@lists.php.net to get a copy of this message
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: $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. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#278616) next »