Reputation: 13
I have array with paths:
array (size=27692)
0 => string './users/58/576709/16376/16376.mp4'
(length=34)
1 => string './users/58/578974/45475/45475.mp4'
(length=34)
//...
How i can get for example 16376.mp4
?
Upvotes: 1
Views: 155
Reputation: 83
This can be done using the following code:
$array = array(
0 => '/users/58/576709/16376/16376.mp4',
1 => '/users/58/576709/16376/16377.mp4'
);
echo $array[1];
$array = explode('/', $array[1]);
echo $array[sizeof($array) - 1];
Last line would print the filename
Upvotes: 0
Reputation: 1828
$path = '/www/public_html/index.html';
$filename = substr(strrchr($path, "/"), 1);
Could also work so for array.
foreach($filepaths as $path){
$filename[] = substr(strrchr($path, "/"), 1);
}
This would give you a new array containing only the filename
Upvotes: 0
Reputation: 313
Try this
$str = "./users/58/576709/16376/16376.mp4";
echo end(explode('/', $str));
Upvotes: 1
Reputation: 59681
This should work for you:
<?php
$str = "./users/58/576709/16376/16376.mp4";
echo basename($str);
?>
Output:
16376.mp4
And if you have a Array, as an example:
<?php
$arr = array("./users/58/576709/16376/16376.mp4", "./users/58/578974/45475/45475.mp4");
foreach($arr as $v)
echo basename($v) . "<br />";
?>
Output:
16376.mp4
45475.mp4
Upvotes: 2