Created
January 25, 2011 17:09
-
-
Save avalanche123/795230 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// extract file name and path from a full file path /tmp/images/image.jpg | |
$path = '/tmp/images/image.jpg'; | |
list($name, $dir) = array_map('strrev', explode(DIRECTORY_SEPARATOR, strrev(str_replace('/', DIRECTORY_SEPARATOR, $path)), 2)); | |
// or , thanks to @nicholascloud | |
list($dir, $name) = array_values(pathinfo($path)); |
updated :)
list($dir, $name) = pathinfo($path);
;)
that wouldn't work as list only accepts numerically indexed array, and cannot work with associative one, hence the array_values(...)
relying on the value order in array_values seems a bit ugly :-/
what about
list($dir, $name) = array(pathinfo($path, PATHINFO_DIRNAME), pathinfo($path, PATHINFO_FILENAME));
didn't tested :)
how 'bout
$dir = pathinfo($path, PATHINFO_DIRNAME);
$name = pathinfo($path, PATHINFO_FILENAME);
seems pretty straightforward :)
you guys win:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm with @nicholascloud :)