note 34494 deleted from function.strcspn by didou
| From: | didou@php.net | Date: | Tue, 29 Jul 2003 09:05:47 +0000 |
| Subject: | note 34494 deleted from function.strcspn by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52890@lists.php.net to get a copy of this message | ||
Note Submitter: geraldp@sigaw.net
----
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.