note 16353 added to function.octdec

From: Date: Fri, 26 Oct 2001 00:03:38 +0000
Subject: note 16353 added to function.octdec
Groups: php.notes 
Request: Send a blank email to php-notes+get-19453@lists.php.net to get a copy of this message
This function and decoct work great when working with file permissions. For example: <?php $mode = octdec('4750'); $user['suid'] = ($mode & 04000); $user['read'] = ($mode & 00400); $user['write'] = ($mode & 00200); $user['execute'] = ($mode & 00100); $group['sgid'] = ($mode & 02000); $group['read'] = ($mode & 00040); $group['write'] = ($mode & 00020); $group['execute'] = ($mode & 00010); $other['text'] = ($mode & 01000); $other['read'] = ($mode & 00004); $other['write'] = ($mode & 00002); $other['execute'] = ($mode & 00001); $attrs = array('-','-','-','-','-','-','-','-','-','-'); if ($system['dir']) $attrs[0] = 'd'; if ($user['read']) $attrs[1] = 'r'; if ($user['write']) $attrs[2] = 'w'; if ($user['execute']) $attrs[3] = 'x'; if ($user['suid']) $attrs[3] = 'S'; if ($group['read']) $attrs[4] = 'r'; if ($group['write']) $attrs[5] = 'w'; if ($group['execute']) $attrs[6] = 'x'; if ($group['sgid']) $attrs[6] = 'S'; if ($other['read']) $attrs[7] = 'r'; if ($other['write']) $attrs[8] = 'w'; if ($other['execute']) $attrs[9] = 'x'; if ($other['text']) $attrs[9] = 'T'; echo '<pre>'; echo 'Mode Decimal: ' . $mode . "\n"; echo 'Mode Octal: ' . decoct($mode) . "\n"; echo 'Mode String: ' . implode('',$attrs)."\n"; echo '</pre>'; ?> Outputs: Mode Decimal: 2536 Mode Octal: 4750 Mode String: -rwSr-x--- -Mike -- http://www.php.net/manual/en/function.octdec.php http://master.php.net/manage/user-notes.php?action=edit+16353 http://master.php.net/manage/user-notes.php?action=delete+16353 http://master.php.net/manage/user-notes.php?action=reject+16353

« previous php.notes (#19453) next »