用php从字符串中找到文件名 [英] find the filename from a string with php
本文介绍了用php从字符串中找到文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public/images/portfolio/i-vis/1.jpg
无论使用php的文件名如何,我如何删除所有路径?
How could i remove all the path regardless of what the filename is using php?
推荐答案
看看 basename()
$path = 'public/images/portfolio/i-vis/1.jpg'
$name = basename($path); // $name == '1.jpg'
此外, dirname()
获取另一部分
Also, dirname()
fetches the other part
$dir = dirname($path); // $dir == 'public/images/portfolio/i-vis'
如果您需要更多信息-有 pathinfo()
If you need even more information - there is pathinfo()
$info = pathinfo($path);
var_dump($info);
产生
array(4) {
["dirname"]=>
string(29) "public/images/portfolio/i-vis"
["basename"]=>
string(5) "1.jpg"
["extension"]=>
string(3) "jpg"
["filename"]=>
string(1) "1"
}
所以$info['filename']
给您的文件没有扩展名.
So $info['filename']
gives you the file without the extension.
这篇关于用php从字符串中找到文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文