note 25101 deleted from function.realpath by aidan
| From: | aidan@php.net | Date: | Sun, 29 Aug 2004 21:51:45 +0000 |
| Subject: | note 25101 deleted from function.realpath by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75617@lists.php.net to get a copy of this message | ||
Note Submitter: michael at cannonbose dot com
----
Function to convert some path from PHP function into a working Window's path. This is a quick
fix to my include problem and therefore may not be thuroughly tested.
/**
* windows_path_fix($path)
*
* Fix $path to work on windows machines.
*
* @param $path URI from PHP function, ex: getcwd(), 'c:/documents/files/'
* @return string
*/
function windows_path_fix($path)
{
// is this running on a Windows machine
// look at $_ENV['OS']
if ( isset($_ENV['OS']) && preg_match('/window/i',
$_ENV['OS']) )
{
// if Windows...
// convert forward slashes '/' to back slashes '\'
$path = preg_replace('/\//', '\\', $path);
}
return $path;
}
Actual usage case:
// this file's document root based upon server or internal location
// hard code
// $doc_root = '/htdocs/www';
// automate
$doc_root = ( $_SERVER['DOCUMENT_ROOT'] )
? $_SERVER['DOCUMENT_ROOT']
: getcwd();
// this file's module directory location
$mod_dir = '/';
// Cannon BOSE common methods directory
$cb_dir = 'cb_common/';
// CB file's location
$file_location = $doc_root . $mod_dir . $cb_dir;
$file_location = windows_path_fix($file_location);