Re: splitting a string
| From: | Daniel Egeberg | Date: | Tue, 05 Jan 2010 13:15:39 +0000 |
| Subject: | Re: splitting a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300809@lists.php.net to get a copy of this message | ||
On Tue, Jan 5, 2010 at 13:39, Ingleby, Les <les.ingey@tynemet.ac.uk> 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.
There are a couple of ways you could do this. The most straightforward
way would be to use the pathinfo() function.
<?php
$file = 'word_document.docx';
$extension = pathinfo($file, PATHINFO_EXTENSION);
$name = pathinfo($file, PATHINFO_FILENAME);
?>
See http://php.net/pathinfo for more information about that
function.
You could also explode() it and do something with that, or you could
or use some of the other many string manipulation functions. I think
pathinfo() is easiest.
--
Daniel Egeberg