Re: Re: splitting a string
| From: | Shawn McKenzie | Date: | Tue, 05 Jan 2010 15:09:04 +0000 |
| Subject: | Re: Re: splitting a string | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300816@lists.php.net to get a copy of this message | ||
Ashley Sheridan wrote:
> 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
>
>
Well I thought about that when I posted. If all you're concerned about
is the filename then my first example works great, for the second to get
the full extension you would set a limit to only return the first part
before the . and then all the rest (assuming that the rest is the
extension):
list($filename, $extension) = explode('.', 'archive.tar.gz', 2);
Of course this doesn't work for something like 'My.Word.Document.docx'
or 'archive_v2.0.1.tar.gz', but I don't know what will with extensions
being variable length and possibly composed of multiple periods.
--
Thanks!
-Shawn
http://www.spidean.com