note 84006 modified in function.get-included-files by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 00:02:00 +0000 |
| Subject: | note 84006 modified in function.get-included-files by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141816@lists.php.net to get a copy of this message | ||
If you want to get the relative path of an included file, from within itself use this function. If
you ever have a include file thats path may not be static, this can save some time.
<?php
function get_current_files_path($file_name)
{
//find the current files directory
$includes = get_included_files();
$path = "";
for ($i=0; $i < count($includes); $i++)
{
$path = strstr($includes[$i], $file_name);
if ($path != false)
{
$key = $i;
break;
}
}
$path = str_replace(getcwd(), "", $includes[$key]);
$path = str_replace("\\", "/", $path);
$path = str_replace($file_name, "", $path);
$path = ltrim($path, "/");
return $path;
}
?>
--was--
If you want to get the relative path of an included file, from within itself use this function. If
you ever have a include file thats path may not be static, this can save some time.
function get_current_files_path($file_name)
{
//find the current files directory
$includes = get_included_files();
$path = "";
for ($i=0; $i < count($includes); $i++)
{
$path = strstr($includes[$i], $file_name);
if ($path != false)
{
$key = $i;
break;
}
}
$path = str_replace(getcwd(), "", $includes[$key]);
$path = str_replace("\\", "/", $path);
$path = str_replace($file_name, "", $path);
$path = ltrim($path, "/");
return $path;
}
http://php.net/manual/en/function.get-included-files.php