note 73323 deleted from function.filetype by colder
| From: | colder@php.net | Date: | Sun, 18 Feb 2007 14:05:01 +0000 |
| Subject: | note 73323 deleted from function.filetype by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123536@lists.php.net to get a copy of this message | ||
Note Submitter: jchonlasith at yahoo dot com
Reason: bad code
----
Here is my function to get the filename information.
function get_filename_info($filepath)
{
$last_slash = strlen($filepath) - strlen(strrchr($filepath, "/"));
$path_name = ($last_slash === FALSE)?"":substr($filepath, 0, $last_slash + 1);
$file_name_with_ext = ($last_slash === FALSE)?$filepath:substr($filepath, $last_slash + 1);
$last_dot = strlen($file_name_with_ext) - strlen(strrchr($file_name_with_ext, "."));
$file_name = ($last_dot === FALSE)?"":substr($file_name_with_ext, 0, $last_dot);
$file_ext = ($last_dot === FALSE)?$file_name_with_ext:substr($file_name_with_ext, $last_dot + 1);
return array("FILEPATH" => $filepath,
"PATH" => $path_name,
"FILENAMEEXT" => $file_name_with_ext,
"FILENAME" => $file_name,
"FILEEXT" => $file_ext);
}
// testing
$filepath = "/usr/local/apache/htdocs/this.is.my.filename.php";
$filename_info = get_filename_info($filepath);
var_dump($filename_info);
// output
array(5) {
["FILEPATH"]=>
string(48) "/usr/local/apache/htdocs/this.is.my.filename.php"
["PATH"]=>
string(25) "/usr/local/apache/htdocs/"
["FILENAMEEXT"]=>
string(23) "this.is.my.filename.php"
["FILENAME"]=>
string(19) "this.is.my.filename"
["FILEEXT"]=>
string(3) "php"
}
Hope this may help you.
Chonla!!