note 34538 added to function.strspn
| From: | dominik at matrixstrom dot com | Date: | Wed, 30 Jul 2003 09:25:52 +0000 |
| Subject: | note 34538 added to function.strspn | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52995@lists.php.net to get a copy of this message | ||
// 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! */
----
Manual Page -- http://www.php.net/manual/en/function.strspn.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34538
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34538&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34538&report=yes