[PATCH] proposal for new function (str_type)

php.internals

Evan Nemerson

22 years ago
Hi everyone, I've attached a patch which adds a function that basically wraps the ctype.h functions. It pretty much just lets you check to see if a string contains only a certain set of characters. I think it would be very nice for input validation, particularly for those who fear regular expressions. Here's the prototype: bool str_type(str subject, int type) type is a bitmask created from a bunch of new constants (STR_TYPE_ALNUM, STR_TYPE_ALPHA, STR_TYPE_CNTRL, STR_TYPE_DIGIT, STR_TYPE_GRAPH, STR_TYPE_LOWER, STR_TYPE_PRINT, STR_TYPE_PUNCT, STR_TYPE_SPACE, STR_TYPE_UPPER, STR_TYPE_XDIGIT) If anyone is interested, there's a more exotic version at http://www.coeus-group.com/en/uploads/php_str_type.2.diff which allows as many parameters as you want, each of which can be either one of the above constants or a bitmask. It's not as clean as the attached version, and the attached version is definitely more similar to other functions, but I thought this way would be nice for people who are intimidated by bitmasks. If the attachment doesn't agree with anyone, it's also at http://www.coeus-group.com/en/uploads/php_str_type.1.diff
-- Evan Nemerson evan@coeus-group.com -- "The greatest mistake is to imagine that the human being is an autonomous individual. The secret freedom which you can supposedly enjoy under a despotic government is nonsense, because your thoughts are never entirely your own. Philosophers, writers, artists, even scientists, not only need encouragement and an audience, they need constant stimulation from other people. It is almost impossible to think without talking. If Defoe had really lived on a desert island, he could not have written Robinson Crusoe, nor would he have wanted to. Take away freedom of speech, and the creative faculties dry up." -George Orwell

Hartmut Holzgraefe

22 years ago
Evan Nemerson wrote:
> Hi everyone, > > I've attached a patch which adds a function that basically wraps the ctype.h > functions.
http://php.net/manual/en/ref.ctype.php

Evan Nemerson

22 years ago
On Friday 21 November 2003 02:14 pm, Hartmut Holzgraefe wrote:
> Evan Nemerson wrote: > > Hi everyone, > > > > I've attached a patch which adds a function that basically wraps the > > ctype.h functions. > > http://php.net/manual/en/ref.ctype.php
Sara Golemon pointed that out, too. Those functions don't allow you to check more than one at the same time. I did, however, make a new patch that is named ctype() and is is in ext/ctype. Unfortunately, it got top-posted (I think Sara sent to php-internals@ on accident, and I replied to internals@...), but it's there.
-- Evan Nemerson evan@coeus-group.com