Advertisement
jargon

// Shared :: "Linedancer 2/Unix Compliance.php"

Nov 3rd, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | Gaming | 0 0
  1. <?php
  2. // Shared :: "Linedancer 2/Unix Compliance.php"
  3.  
  4. function UnixAdjust($path){
  5.    
  6.     $path = str_replace("\\","/",$path);
  7.     $adjusted = "";
  8.    
  9.     for($offset = 0; $offset < strlen($path); $offset++){
  10.        
  11.         $c = substr($path,$offset,1);
  12.        
  13.         $upper = strtoupper($c);
  14.         $lower = strtolower($c);
  15.        
  16.         if($upper !== $lower){
  17.             $adjusted .= "[{$upper}{$lower}]";
  18.         }else{
  19.             $adjusted .= "{$c}";
  20.         }
  21.     }
  22.     return $adjusted;
  23. }
  24.  
  25. function UnixNormalized($path){
  26.    
  27.     $path = UnixAdjust($path);
  28.    
  29.     if(substr($path,0,strlen("{$_SERVER['DOCUMENT_ROOT']}")) === "{$_SERVER['DOCUMENT_ROOT']}"){
  30.         $path = substr($path,strlen("{$_SERVER['DOCUMENT_ROOT']}")) === "{$_SERVER['DOCUMENT_ROOT']}";     
  31.     }
  32.  
  33.     while(substr($path,0,1) == "/"){
  34.         $path = substr($path,1);
  35.     }
  36.    
  37.     $parts = explode("/",$path);
  38.    
  39.     $parts = explode("/",$path);
  40.     $adjusted = "";
  41.    
  42.     $normalized = "{$_SERVER['DOCUMENT_ROOT']}";       
  43.    
  44.     foreach($parts as $part){
  45.         if(glob("{$normalized}/{$part}",GLOB_ONLYDIR)){
  46.             $normalized.="/{$part}";
  47.         }elseif(glob("{$normalized}/{$part}")){
  48.             $normalized.="/{$part}";
  49.             break;
  50.         }
  51.     }
  52.    
  53.     return $normalized;
  54. }
  55.  
  56. function UnixPath($path){
  57.     $normalized = UnixNormalized($path);
  58.     return glob($normalized)[0];
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement