note 34538 deleted from function.strspn by nlopess
| From: | nlopess@php.net | Date: | Thu, 08 Jan 2004 16:11:21 +0000 |
| Subject: | note 34538 deleted from function.strspn by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63155@lists.php.net to get a copy of this message | ||
Note Submitter: dominik@matrixstrom.com
----
// if you want to limit the user to only using allowed chars:
function msCheckStrCharsOnly ($myuserstr,$myallowedchars) {
$myres=TRUE;
$mycheck=strspn($myuserstr,$myallowedchars);
if(strlen($myuserstr) != $mycheck) $myres=FALSE;
return $myres;
}
// our allowed chars will be:
$charsallowed='ABCDEFGHIJKLMOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
// check the string 'This is a test' if it contains allowed chars only
if (msCheckStrCharsOnly('This is a test',$charsallowed)) echo ('No invalid Chars
contained');
else echo('ERROR: contains invalid chars!');
/* this will print 'ERROR: contains invalid chars!' because the ' ' (space) char
is not allowed! */