includes/functions.php
changeset 851 b98798f6572d
parent 842 f13bb4f21890
child 857 f3a5a276208c
equal deleted inserted replaced
850:ccedb36dd929 851:b98798f6572d
  5000     return true;
  5000     return true;
  5001   }
  5001   }
  5002   return false;
  5002   return false;
  5003 }
  5003 }
  5004 
  5004 
       
  5005 /**
       
  5006  * Implementation of the "which" command in native PHP.
       
  5007  * @param string command
       
  5008  * @return string path to executable, or false on failure
       
  5009  */
       
  5010 
       
  5011 function which($executable)
       
  5012 {
       
  5013   $path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
       
  5014   if ( !$path )
       
  5015     // couldn't get OS's PATH
       
  5016     return false;
       
  5017     
       
  5018   $win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
       
  5019   $extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
       
  5020   $separator = $win32 ? ';' : ':';
       
  5021   $paths = explode($separator, $path);
       
  5022   foreach ( $paths as $dir )
       
  5023   {
       
  5024     foreach ( $extensions as $ext )
       
  5025     {
       
  5026       $fullpath = "$dir/{$executable}{$ext}";
       
  5027       if ( file_exists($fullpath) && is_executable($fullpath) )
       
  5028       {
       
  5029         return $fullpath;
       
  5030       }
       
  5031     }
       
  5032   }
       
  5033   return false;
       
  5034 }
       
  5035 
  5005 ?>
  5036 ?>