note 27000 deleted from function.strcspn by aidan

From: Date: Fri, 27 Aug 2004 09:23:26 +0000
Subject: note 27000 deleted from function.strcspn by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75410@lists.php.net to get a copy of this message
Note Submitter: php at nospam dot mike2k dot com ---- 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.

« previous php.notes (#75410) next »