2010/1/5 Ashley Sheridan <a...@ashleysheridan.co.uk>: > On Tue, 2010-01-05 at 08:45 -0600, Shawn McKenzie wrote: > >> Ingleby, Les wrote: >> > Hi all, first time I have posted here so please be nice. >> > >> > I am using PEAR HTTP_Upload to handle multiple file uploads. What I need >> > to do is to take the file name which is output using the getProp() >> > function and then remove the file extension from the end of the file for >> > example: >> > >> > Original name held in the getProp() array [name] "word_doccument.docx" >> > >> > I need to put this into a string such as >> > >> > $filename = $props['name']; >> > >> > I then need to separate the file name from the file extension. >> > >> > I have been reading the php manual do please don't bother referring me to >> > that. >> > >> > Thanks in advance. >> > >> > LEGAL INFORMATION >> > Information contained in this e-mail may be subject to public disclosure >> > under the Freedom of Information Act 2000. Unless the information is >> > legally exempt, the confidentiality of this e-mail and your reply cannot >> > be guaranteed. >> > Unless expressly stated otherwise, the information contained in this >> > e-mail & any files transmitted with it are intended for the recipient >> > only. If you are not the intended recipient you must not copy, distribute, >> > or take any action or reliance upon it. If you have received this e-mail >> > in error, you should notify the sender immediately and delete this email. >> > Any unauthorised disclosure of the information contained in this e-mail is >> > strictly prohibited. Any views or opinions presented are solely those of >> > the author and do not necessarily represent those of Tyne Metropolitan >> > College unless explicitly stated otherwise. >> > This e-mail and attachments have been scanned for viruses prior to leaving >> > Tyne Metropolitan College. Tyne Metropolitan College will not be liable >> > for any losses as a result of any viruses being passed on. >> > >> >> list($filename) = explode('.', $props['name']); >> >> Or if you may need the extension: >> >> list($filename, $extension) = explode('.', $props['name']); >> >> -- >> Thanks! >> -Shawn >> http://www.spidean.com >> > > > I just though. How would all these methods fare when given a file like > archive.tar.gz, where the .tar.gz is the full extension, not just > the .gz? > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > >
<?php $file = 'archve.tar.gz'; $pathinfo_extension = pathinfo($file, PATHINFO_EXTENSION); $pathinfo_name = pathinfo($file, PATHINFO_FILENAME); $substr_right_name = substr($file, 0, strrpos($file, '.')); $substr_right_extension = substr($file, strrpos($file, '.')); $substr_left_name = substr($file, 0, strpos($file, '.')); $substr_left_extension = substr($file, strpos($file, '.')); list($list_name, $list_extension) = explode('.', $file); echo " Original : $file Pathinfo : $pathinfo_name / $pathinfo_extension Substr (right) : $substr_right_name / $substr_right_extension Substr (left) : $substr_left_name / $substr_left_extension List : $list_name / $list_extension "; ?> outputs ... Original : archve.tar.gz Pathinfo : archve.tar / gz Substr (right) : archve.tar / .gz Substr (left) : archve / .tar.gz List : archve / tar The only option that seems to be working here (and one that wasn't previously suggested) is to use $substr_left_name = substr($file, 0, strpos($file, '.')); $substr_left_extension = substr($file, strpos($file, '.')); -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php