galacnet
02-26-2005, 01:57 PM
Hello,
Does any know if php is able to get the file name and then place it into a variable minus the extension?
eg.
Get file name
$value = File Name
$name - .html = $finalvalue
Thanks for the help.
Tried php.net but can find the command.... :bawling:
thartdyke
02-26-2005, 02:02 PM
I'd probably do an explode on ".", then delete the last element of the array, and do an implode with "."
That should take care of file.names.like.this.html
After I'd read the manual ( :) ) I'd do this:
$path = "/home/httpd/html/index.php";
$file = basename($path, ".html");
galacnet
02-26-2005, 02:16 PM
A search on php.net I found this
<?php
$file = basename ($PHP_SELF);
$file = explode(".php",$file);
?>
So the above if the filename is abc.123.php will become abc.123 after explode is set on .php?
thartdyke
02-26-2005, 02:37 PM
I guess that'll work, but at first sight, it's not so intuitive! It's using ".php" as the delimiter for explode.
You may as well do it in 1 line:
$file = basename ($PHP_SELF, ".php");
galacnet
02-26-2005, 02:38 PM
Ah Got it.
thanks for the help.
eric1207
02-26-2005, 02:39 PM
<?
$file = "blah.php";
$filename = strtok($file, ".");
echo $filename; // blah
?>
but you wouldn't be able to see the extension at all anymore