The simplest way I can think of is to go through the directory and check each file, like so:
// returns true on success, false if no file found
function rename_anyExt($directory, $filename, $newFilename) {
$dirPointer = opendir($directory);
while ($item = readdir($dirPointer)) {
$extStart = strrpos($item, '.'); // get start position of extension (if existant)
$sansExt = $extStart ? substr($item, 0, $extStart) : $item; // get filename without extension
if ($sansExt == $filename) { // if it's a match, rename the file and end this function
$ext = $extStart ? substr($item, $extStart) : ''; // get extension, if existant
rename($directory.$item, $directory.$newFilename.$ext);
return true;
}
}
return false; // no matching file was found
}
I didn't test this, let me know if there are issues. Also, this function will stop once it finds the first matching file, since it sounds like you're only expecting there to be one file.