Re: Re: splitting a string
| From: | Richard Quadling | Date: | Tue, 05 Jan 2010 15:17:59 +0000 |
| Subject: | Re: Re: splitting a string | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300818@lists.php.net to get a copy of this message | ||
2010/1/5 Ingleby, Les <les.ingey@tynemet.ac.uk>:
> Hi everyone, thanks so much for your help. The pathinfo($filename, PATHINFO_FILENAME); works a
> treat for me, since I am dealing and will only be dealing with a word doc then this is awesome.
>
> Still new to PHP but self taught and scripting is coming on hence I don't know many
> functions just yet.
>
> -----Original Message-----
> From: Shawn McKenzie [mailto:nospam@mckenzies.net]
> Sent: 05 January 2010 15:09
> To: ash@ashleysheridan.co.uk
> Cc: Ingleby, Les; php-general@lists.php.net
> Subject: Re: [PHP] Re: splitting a string
>
> 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
>
> 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.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Make sure you check out the documentation at http://www.php.net/manual/en.
You can use http://www.php.net/function_name_here as a short
cut -
e.g. http://www.php.net/substr
Pick one of the functions we've mentioned and follow the "See also"
for other related functions.
Regards,
Richard.
--
-----
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