note 78224 modified in function.realpath by danbrown

From: Date: Mon, 01 Jun 2009 13:00:12 +0000
Subject: note 78224 modified in function.realpath by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156230@lists.php.net to get a copy of this message
Sometimes it is helpful to check for the existance of a file which might be found by using the include_path like in <?php include("file_from_include_path.php"); ?> A simple function iterates the include_path and tries all possibilites, returns translated_local_path on success or false if not found. <?php function mappath($path_to_translate){ $IncludePath=explode(PATH_SEPARATOR,get_include_path()); foreach($IncludePath as $prefix){ if(substr($prefix,-1)==DIRECTORY_SEPARATOR) $prefix=substr($prefix,0,-1); $try_path=sprintf("%s%s%s" ,$prefix,DIRECTORY_SEPARATOR,$path_to_translate); if(file_exists($try_path))return($try_path); } return false; } ?> --was-- Sometimes it is helpful to check for the existance of a file which might be found by using the include_path like in <?php include("file_from_include_path.php"); ?> A simple function iterates the include_path and tries all possibilites, returns translated_local_path on success or false if not found. <?php function mappath($path_to_translate){ $IncludePath=explode(PATH_SEPARATOR,get_include_path()); foreach($IncludePath as $prefix){ if(substr($prefix,-1)==DIRECTORY_SEPARATOR) $prefix=substr($prefix,0,-1); $try_path=sprintf("%s%s%s" ,$prefix,DIRECTORY_SEPARATOR,$path_to_translate); if(file_exists($try_path))return($try_path); } return false; } ?> http://php.net/manual/en/function.realpath.php

« previous php.notes (#156230) next »