Hi,
I have written a "Permission Converter" which converts unix permissions (the
ones we know from CHMOD) into a "-" delimited string of numbers. I also made
it that it supports one more level (unix only has 3 different types of
permissions, (r,w,x) while mine can handle a fourth one. Since I'm just a
newbie to PHP, I was wondering whether there is a shorter way of achieving
the same thing. Here is my code:
// $num is the number (range: 1-15)
$done = "";
$result = "";
while ($done != 1) {
if ($num > 8) {
$num = $num - 8;
$result = "8-";
} elseif ($num == 8) {
$result = 8;
$done = 1;
} elseif ($num > 4) {
$num = $num - 4;
$result .= "4-";
} elseif ($num == 4) {
$result .= 4;
$done = 1;
} elseif ($num > 2) {
$result .= "2-1";
$done = 1;
} elseif ($num == 2) {
$result .= "2-";
$done = 1;
} else {
$result .= "1";
$done = 1;
}
}
if ((strrpos($result, "-") == strlen($result)-1) && strlen($result) > 1) {
$result = strrev($result);
$result = substr($result, 1);
$result = strrev($result);
}
echo $result;
TIA,
Raphael
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]