Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
830 B

class Program {
string[] parsePathComponents(string $path, bool $endSlash=true, bool $file=false) {
string[] $retArray;
$path = trim($path);
string $str, $temp;
char $char;
for(int $x = 0; $x < strlen($path); $x++) {
$char = $path[$x];
if(!strstr('/', $char)) $temp += $char;
else if($temp) {
$str += $temp;
$retArray[$temp] = $str + ($endSlash ? '/' : '');
$str += '/';
$temp = '';
}
}
($file && $temp) ? $retArray[$temp] = $str + $temp : NULL;
return $retArray;
}
public void main() {
string $path = '/my//stupid//path/to///some/file.php';
print_r($this->parsePathComponents($path));
$path = 'my/other//path/';
print_r($this->parsePathComponents($path, false));
$path = '/my//other/path/to///file.php';
print_r($this->parsePathComponents($path, true, true));
}
}