Re: Substr function
| From: | tg-php at gryffyndevelopment dot com | Date: | Tue, 14 Dec 2004 14:20:40 +0000 |
| Subject: | Re: Substr function | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-25155@lists.php.net to get a copy of this message | ||
In addition to substr() and explode() already mentioned, check out some of these:
basename() - Returns filename component of path
http://us2.php.net/manual/en/function.basename.php
strrpos() - Find position of last occurrence of a char in a string
http://us2.php.net/manual/en/function.strrpos.php
$filepath = "/something/somethingelse/filename.ext";
You could use basename() to get the full filename with exension then use
$basename = basename($filepath);
Or you could use:
$basename = substr(strrpos($filepath,"/")+1);
Then use:
list($file,$ext) = explode(".",$basename);
.. to get your extension.
I think that's right. If you don't do the +1, I believe you'll get the "/"
in your filename and you don't want that part.
I think basename() is probably your best bet if you have the full file path to start with. substr()
works great if you know where to split the string but using PHP's functions to their fullest
capability is always good tood.
Good luck! HTH!
-TG
*** new email address tg-php@gryffyndevelopment.com
*** old email address tgryffyn@air-cargo-inc.com (Stupid Chapter 11)
= = = Original message = = =
Hi can anyone explain to me how to manipluate strings. I have generated
a file name
($_FILES['documenturl']['name'])
Out of this server variable I need to grab the file and the extension
and put them into seperate fields for database upload. Any idea how to
do this by using substr?
Thanks
Steven
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.