2013-02-27 42 views

回答

4

我建議你檢查,而不是使用正則表達式

echo basename("uploads/1/0/1/7/10178123/4320885_orig.png"); 

//result: 4320885_orig.png 
2

不要使用正則表達式,使用pathinfo PHP的Basename功能...

echo pathinfo('uploads/1/0/1/7/10178123/4320885_orig.png', PATHINFO_BASENAME); 
0

嘗試pathinfo()

$path = 'uploads/1/0/1/7/10178123/4320885_orig.png'; 

echo pathinfo($path, PATHINFO_BASENAME); //png 

您還可以獲得路徑的其他組件:

$path_parts = pathinfo($path); 

echo $path_parts['extension'], "\n"; //png 
echo $path_parts['dirname'], "\n"; //uploads/1/0/1/7/10178123 
echo $path_parts['basename'], "\n"; //4320885_orig.png 
echo $path_parts['filename'], "\n"; //4320885_orig 

查看PHP documentation on pathinfo()瞭解更多信息。