note 27000 added to function.strcspn
| From: | php at nospam dot mike2k dot com | Date: | Wed, 20 Nov 2002 04:39:37 +0000 |
| Subject: | note 27000 added to function.strcspn | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39728@lists.php.net to get a copy of this message | ||
this is an awesome function if you want to test letter-based modes or roles, i.e.:
function check_access($required_roles,$user_roles) {
if(strcspn($required_roles,$user_roles) == strlen($required_roles)) {
print "no access. do your lockout routine here or die().";
} else {
print "access granted.";
}
}
so say you have roles for u = user, a = admin, s = superadmin, and you want to make sure the user is
an admin OR superadmin, and the user is only "u" - it will return false:
checkaccess("as",$user_roles)
but if they have "a" it will be true.. i'm sure you could use the strspn() function
to make sure the ANDs work, but i only used ORs in my situation. almost kinda like doing bitwise on
the alphabet.
--
http://www.php.net/manual/en/function.strcspn.php
http://master.php.net/manage/user-notes.php?action=edit+27000
http://master.php.net/manage/user-notes.php?action=delete+27000
http://master.php.net/manage/user-notes.php?action=reject+27000