- pathinfo: documentation ( source)
- var_dump: documentation ( source)
<?php
function replaceFileName($input, $newFileName) {
$info = pathInfo($input);
return $info['dirname'] . DIRECTORY_SEPARATOR . $newFileName . '.' . $info['extension'];
}
$test = "/txt/txt/txt/txt.txt";
var_dump(replaceFileName($test, 'testing'));