Re: appreciation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux