|
Posted by Curtis on 02/23/07 23:53
Toby A Inkster wrote:
> laredotornado@zipmail.com wrote:
>
>> Good question. You can assume for the purposes of this question that
>> extension is anything following the "." in which there will be exactly
>> one "." in the file name.
>
> $x = pathinfo('/path/to/file.txt');
> $X = $x['dirname'] . '/' . 'foo' . '.' . $x['extension'];
> print $X;
>
A little more involved, but this will allow for extensions like tar.gz
or tar.bz2, etc. It gets the position in the file name, of the first
".", and keeps everything after.
$p = '/path/to/archive.tar.gz';
$file = basename($p);
$p2 = dirname($p) . '/newname' . substr($file,strpos($file,'.'));
echo $p2;
--
Curtis, http://dyersweb.com
[Back to original message]
|