note 45565 deleted from function.pathinfo by aidan
| From: | aidan@php.net | Date: | Sat, 11 Sep 2004 07:36:33 +0000 |
| Subject: | note 45565 deleted from function.pathinfo by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76441@lists.php.net to get a copy of this message | ||
Note Submitter: Frans van 't Hof, The Netherlands
----
This functions returns Unix like formatted paths for both Unix/Linux and Windows based servers. The
function is tested on Debian Linux and Windows XP with PHP 4.3.8.
The function retrieves the current path of where the script is located and transforms it. Hopefully
it's useful to you and easy to adapt.
Pre-condition: none.
Post-condition: Unix like path on the current script.
--------------
function absolute_path () {
$cur_path = strtr(getcwd(),"\\","/");
// Provide in A: t/m Z:
if ( $cur_path{1} == ":" ) {
$i = strlen($cur_path) - 1;
if ($cur_path{$i} <> "/") {
$cur_path = $cur_path . "/";
}
return (substr($cur_path,2,strlen($cur_path)));
// Provide in AA: t/m ZZ:
} else if ( $cur_path{2} == ":" ) {
$i = strlen($cur_path) - 1;
if ($cur_path{$i} <> "/") {
$cur_path = $cur_path . "/";
}
return (substr($cur_path,3,strlen($cur_path)));
// Provide in AAA: t/m ZZZ:
} else if ( $cur_path{3} == ":" ) {
$i = strlen($cur_path) - 1;
if ($cur_path{$i} <> "/") {
$cur_path = $cur_path . "/";
}
return (substr($cur_path,4,strlen($cur_path)));
} else {
$i = strlen($cur_path) - 1;
if ($cur_path{$i} <> "/") {
$cur_path = $cur_path . "/";
}
// Assuming a non Windows platform.
return $cur_path;
}
}