从文件中删除扩展名 [英] remove extension from file
问题描述
可能存在重复:
如何从字符串中移除扩展名(仅限真正的扩展名!)
我是全新的php,有很多需要学习的内容!我正在为我们的King County Iris Society网站试验MiniGal Nano。除了一个小例外,它适用于我们的目的:照片文件名称需要在缩略图下可见。我已经创建了一个工作,但它显示了扩展。我已经找到函数的代码示例,但不知道如何将它们合并到现有的代码中。任何援助将不胜感激。
I am brand new to php and have a lot to learn! I'm experimenting with MiniGal Nano for our King County Iris Society website. It work quite well for our purposes with one small exception: the photo file name needs to be visible under the thumbnail. I've created a work around, but it shows the extension. I've found code samples of functions but have no idea how to incorporate them into the existing code. Any assistance would be greatly appreciated.
示例链接: http://www.kcis.org/kcisphotogallery.php?dir=Iris.Japanese
非常感谢! p>
Many thanks!
推荐答案
有几种方法可以做到这一点,但我认为其中一种更快的方法如下所示:
There are a few ways to do it, but i think one of the quicker ways is the following
// $filename has the file name you have under the picture
$temp = explode('.', $filename);
$ext = array_pop($temp);
$name = implode('.', $temp);
另一个解决方案是这样的。我没有测试过它,但它看起来应该在一个文件名中适用多个时段。
Another solution is this. I haven't tested it, but it looks like it should work for multiple periods in a filename
$name = substr($filename, 0, (strlen($filename))-(strlen(strrchr($filename, '.'))));
另外:
Also:
$info = pathinfo($filename);
$name = $info['filename'];
$ext = $info['extension'];
// Shorter
$name = pathinfo($file, PATHINFO_FILENAME);
// Or in PHP 5.4
$name = pathinfo($filename)['filename'];
在所有这些中, $ name
包含没有扩展名的文件名
In all of these, $name
contains the filename without the extension
这篇关于从文件中删除扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!