> 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:

"-" is probably not the best choice, since most Un*x boxes use "-" to
display "None" of rxw set in "ls" and other human-readable output.  You
would probably win more fans if you just use the same format as "ls"

Also, what's the fourth level for?...  If the OS doesn't support it, I'm
having a hard time figuring out what possible good it does...

> // $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;
> }
>
> }

You probably should be looking at >> and << (bit-shift operators)...

This function can probably be reduced to three lines of code, maybe even
one.

> if ((strrpos($result, "-") == strlen($result)-1) && strlen($result) > 1) {
> $result = strrev($result);
> $result = substr($result, 1);
> $result = strrev($result);
> }
>
> echo $result;

Finally... *WHY* are you doing this?...  I know the whole rwx and octal/hex
notation can be tricky at first, but there's a reason why it's been done
that way for quite a *LONG* time...

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
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]

Reply via email to