[英]Get filename only
I have table : 我有桌子:
==============
|id| document|
==============
|1 | doc1.txt|
|2 | doc2.txt|
==============
I wanna get the document
without the extension. 我想获取不带扩展名的
document
。 here's my code : 这是我的代码:
$query = mysql_query("SELECT document FROM tb ") or die(mysql_error());
while ($row = mysql_fetch_array($query)) {
$filename = $row['document'];
$title = basename($filename);
}
But the rsult of $title
still contain the extension. 但是
$title
仍然包含扩展名。 what's wrong? 怎么了? thank you
谢谢
$title = pathinfo($filename, PATHINFO_FILENAME);
在这种情况下, pathinfo()
更适合
In your code, replace: 在您的代码中,替换为:
$title = basename($filename);
With: 附:
$title = substr($filename, 0, strrpos($filename, "."));
I didn't use pathinfo()
because, you are manipulating a string, and not a filename. 我没有使用
pathinfo()
因为您正在处理一个字符串,而不是文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.