note 60118 added to function.strcspn
| From: | (at_heAThotmai1DOTcom) | Date: | Tue, 27 Dec 2005 10:07:12 +0000 |
| Subject: | note 60118 added to function.strcspn | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100774@lists.php.net to get a copy of this message | ||
this function can be used like strspn(), except while that can be used to compare a string with an
allowed pattern, this one can be use to compare a string with a FORBIDDEN pattern
so, to know if any forbidden character has a position inside our string, we can use (not tested with
backslashes)...
<?php
// LARGE VERSION
$forbidden="\"\\?*:/@|<>";
if (strlen($filename) != strcspn($filename,$forbidden)) {
echo "you cant create a file with that name!";
}
// SHORT VERSION
if (strlen($filename) - strcspn($filename,"\"\\?*:/@|<>")) {
echo "i told you, you cant create that file";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.strcspn.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60118
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60118&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60118&report=yes
Search -- http://master.php.net/manage/user-notes.php