[英]How get filename from path php?
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
? 我怎么能得到例如16376.mp4
?
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
Try this 尝试这个
$str = "./users/58/576709/16376/16376.mp4";
echo end(explode('/', $str));
$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 这将为您提供一个仅包含文件名的新数组
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 最后一行将打印文件名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.