note 39855 added to function.strspn
| From: | ronq dot NOSPAM at arnet dot com dot ar | Date: | Fri, 13 Feb 2004 02:13:50 +0000 |
| Subject: | note 39855 added to function.strspn | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65074@lists.php.net to get a copy of this message | ||
You can validate a text with this function, restricting the allowed characters of the input, I use
it to avoid malicious or wrong form submissions. This is a first issue on security, to be sure that
the data you get is safe to work with.
<?php
function valid($str) {
$validlength=10;
$validmask="abcdefghijklmnopqrstuvwxyz0123456789_-";
$str=strtolower($str);
if (strspn($str, $validmask) == strlen($str) && $validlength >= strlen($str)) {
return true;
} else {
return false;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.strspn.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39855
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39855&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39855&report=yes
Search -- http://master.php.net/manage/user-notes.php