Re: appreciation

From: Date: Fri, 12 Oct 2012 11:36:23 +0000
Subject: Re: appreciation
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-319430@lists.php.net to get a copy of this message
On 12-10-2012 06:10, tamouse mailing lists wrote:
if (
        ! is_dir($dirBase."/".$get_the_album) // this is not a directory
     || ! strpos($get_the_album, '.')         // directory name does
not contain a period
     || ! strpos($get_the_album, '\')         // directory name does
not contain a backslash
    )
    {
Don't use ! strpos() to check if it does not contain a character. The reason for this is that: strpos('.text', '.') == false This is because strpos('.something', '.') returns 0, which evaluates to false. So instead, you should use: strpos($get_the_album, '.') !== false to check if $get_the_album does not contain the character '.' However, this is likely not what the OP wants. What he likely does want is to check if the filename is not '.' or '..'. Of course, there are numerous ways to do this. From very simple things like: if ( $filename != '.' && $filename != '..') to if (false === array_search($filename, array('.','..')) { As Lester mentioned, there are tons of ways to resolve a 'problem', and most of them are usually good.

« previous php.general (#319430) next »