[英]regex to find the image name and extension from this url
I have this url which is generated automatically. 我有这个网址是自动生成的。
uploads/1/0/1/7/10178123/4320885_orig.png
I need to get the name and the extension of the image from this url which in this case is 4320885_orig.png 我需要从该URL获取图像的名称和扩展名,在本例中为4320885_orig.png
i am not being able to write a regex to find the name and extension. 我无法编写正则表达式来查找名称和扩展名。
不要使用正则表达式,使用pathinfo
...
echo pathinfo('uploads/1/0/1/7/10178123/4320885_orig.png', PATHINFO_BASENAME);
Try pathinfo()
: 试试
pathinfo()
:
$path = 'uploads/1/0/1/7/10178123/4320885_orig.png';
echo pathinfo($path, PATHINFO_BASENAME); //png
You can get other components of the path as well: 您还可以获取路径的其他组件:
$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
See the PHP documentation on pathinfo()
for more information. 有关更多信息,请参见
pathinfo()
上的PHP文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.