note 45565 added to function.pathinfo
| From: | Fransvan | Date: | Fri, 10 Sep 2004 20:52:14 +0000 |
| Subject: | note 45565 added to function.pathinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76428@lists.php.net to get a copy of this message | ||
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;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.pathinfo.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45565
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45565&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45565&report=yes
Search -- http://master.php.net/manage/user-notes.php