Reputation: 329
I'm writing directory listings and want to get the name of the last directory.
Example:
/data/henry/files/gallery
I only want to get the last directory which is gallery.
I tried with substr('abcdef', 1)
but it's static.
I have an idea of storing the directories into array and then retrieve the last value but how can I do that?
EDIT:
Thanks @deceze for the easy solution.
My solution was longer and not recommended:
$dirarray = explode("/",$row['source']);
$total = count($dirarray);
$sharename = $dirarray[($total-1)];
Upvotes: 0
Views: 286
Reputation: 136
How about using regular expression? Assuming your text is in $text
variable:
preg_match_all("|(/[a-z]+)$|", $text, $result);
$result
will contain /gallery
.
Upvotes: 0