note 34494 added to function.strcspn

From: Date: Tue, 29 Jul 2003 08:58:25 +0000
Subject: note 34494 added to function.strcspn
Groups: php.notes 
Request: Send a blank email to php-notes+get-52889@lists.php.net to get a copy of this message
this function filters an input string $strInput if it contains specific character set $strFilter, this can be useful in processing HTML form inputs: function validateStr($strInput, $strFilter) { $myLen = strLen($strInput); $myTemp = 0; $myRetCode = 0; while ($myTemp<$myLen) { $strA = $strInput{$myTemp}; if (strcspn($strA,$strFilter)) { $myRetCode = 1; } $myTemp++; } return $myRetCode; } this function returns 0 if the input string ONLY contains characters defined in $strFilter; return 1 if it contains any other character(s); Sample 1: echo validateStr("ABC", "ABCDEFGHIJKLMNOPQRSTUVWXYZ") will output 0 since all characters in "ABC" can be found in the filter set. Sample 2: echo validateStr("AbC", "ABCDEFGHIJKLMNOPQRSTUVWXYZ") will output 1 since "b" in "AbC" can be found in the filter set. ---- Manual Page -- http://www.php.net/manual/en/function.strcspn.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34494 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34494&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34494&report=yes

« previous php.notes (#52889) next »