Skip to content

Instantly share code, notes, and snippets.

@favrik
Created September 7, 2012 00:11
Show Gist options
  • Save favrik/3661713 to your computer and use it in GitHub Desktop.
Save favrik/3661713 to your computer and use it in GitHub Desktop.
/**
* $strPathList is in the form of an include_paht: .:/usr/local/lib:etc
*/
function GetValidPathFromList($strPathList) {
$arrPaths = explode(PATH_SEPARATOR, $strPathList);
foreach ($arrPaths as $strPath) {
if (file_exists($strPath)) {
return $strPath;
}
}
return false;
}
/**
* $strPathList is in the form of an include_paht: .:/usr/local/lib:etc
* $strFile is just a filename: file.inc or file.class.php
*/
function IncludeFromPathList($strPathList, $strFile) {
$strPath = GetValidPathFromList($strPathList);
if ($strPath !== false) {
$strComputedFile = $strPath . DIRECTORY_SEPARATOR . $strFile;
include_once $strComputedFile;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment