Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Permissions
- {
- public static function permStringToInt($PermString)
- {
- $strings = str_split($PermString);
- if (count($strings) == 9) {
- $chunks = array_chunk($strings, 3);
- $return_text = "";
- foreach ($chunks as $groups) {
- $group_number = 0;
- foreach ($groups as $permission) {
- if (in_array($permission, array('r', 'w', 'x', '-'))) {
- if ($permission == 'r') {
- $group_number+=4;
- } else if ($permission == 'w') {
- $group_number+=2;
- } else if ($permission == 'x') {
- $group_number+=1;
- }
- } else {
- return "Invalid string!";
- }
- }
- if ($group_number <= 7) {
- $return_text .= $group_number;
- } else {
- return "Invalid string!";
- }
- }
- } else {
- return "Invalid string length!";
- }
- return $return_text;
- //throw new Exception('Not implemented');
- }
- }
- // For test purposes only
- // echo Permissions::permStringToInt("rwxr-x-w-");
- echo Permissions::permStringToInt("rwxrwx---");
- // Should yield 752
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement