Reputation: 647
I have table :
==============
|id| document|
==============
|1 | doc1.txt|
|2 | doc2.txt|
==============
I wanna get the document
without the extension. 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. what's wrong? thank you
Upvotes: 0
Views: 70
Reputation: 167172
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.
Upvotes: 1
Reputation: 254916
$title = pathinfo($filename, PATHINFO_FILENAME);
pathinfo()
is more suitable in this case
Upvotes: 4