$subjectDirectory = '../blogtext/';
$subjectHandle = opendir( $subjectDirectory );
$fileName = $_SERVER['PHP_SELF'];
$tempArray = explode( '-', $fileName );
$finalNum = '-'.$tempArray[1].'-';
$subjectFile;
if( $subjectHandle = opendir( '../blogtext/' ) )
{
/* If you echo $finalNum here, you get '-0-' on the page. */
while( false !== ( $subjectFile = readdir( $subjectHandle ) ) )
{
/* If you echo $finalNum here, you get '-0--0--0--0--0-' on the page. */
if( $subjectFile != '.' && $subjectFile != '..' && !is_dir( $subjectFile ) && strpos( $subjectFile, $finalNum ) )
{
include( $subjectFile );
}
}
closedir( $subjectHandle );
}
Basically, what I’m trying to do is;
get -NUMBER- code from the current file name ( -0-example.php ), and then scan through the directory ( $subjectDirectory ) for the file name that begins with the same code. Then include the file.
I’m unable to do so because the $finalNum changes the code to “code 5 times in a row”, so I can’t find the right file to include.
The reason it’s not working is because
readdir()returns the file name only, not the full path.Try this:
include( $subjectDirectory . $subjectFile );
Re: /* If you echo $finalNum here, you get ‘-0–0–0–0–0-‘ on the page. */
The reason you get this output is because you are echoing $finalNum 5 times. The value of $finalNum is not changing.
EDIT:
I found one more issue in your
ifstatement.strpos( $subjectFile, $finalNum )will return 0 if the $subjectFile starts with $finalNum.Use this instead.