Reply to Re: Renaming a file but preserving the extension

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация