$blogDir = 'blog/';
$blogdirHandle = opendir( $blogDir );
$checkingFile;
$number = 0;
$codeNumber = '-'.$number.'-';
if( $blogdirHandle = opendir( 'blog/' ) )
{
while( ( $checkingFile = readdir( $blogdirHandle ) ) !== false )
{
if( $checkingFile != '.' && $checkingFile != '..' && !is_dir( $checkingFile ) && strpos( $checkingFile, $codeNumber ) !== false )
{
$number++;
}
}
closedir( $blogdirHandle );
}
What I’m trying to do is:
Go through the $blogDir directory, and search for a file that has the same $codeNumber ( -$number- ), and if a file is found, then increase $number by one and search until all files are searched through. For some reason it’s not working. It won’t increase the value of $number, even though there are files with the same $codeNumber in the directory.. Any help?
Once you increment
$number, you need to re-assign$codeNumberinside your loop: