# [PATCH] proposal for new function (str_type)

- Thread: https://externals.io/message/5649
- Original archive: https://news-web.php.net/php.internals/5649
- Started by Evan Nemerson on 2003-11-21T20:42:19+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #5649 — Evan Nemerson — 2003-11-21T20:42:19+00:00

URL: https://externals.io/message/5649#5649

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

---

## #5654 — Evan Nemerson — 2003-11-21T22:10:07+00:00

URL: https://externals.io/message/5649#5654

> > […]
>
> ctype.h
>
> > […]
>
> the
>
> > […]
>
> A couple things:
>
> #1  Have you looked at the ctype extension?
> http://us4.php.net/manual/en/ref.ctype.php

Yeah, but I like being able to use them all at once.

>
> #2 If a unified function is to be added (not against it per se) it should
> probably be named ctype() (as the "top-level" of the ctype extension and be
> placed in ext/ctype rather than in ext/standard/strings.[ch]

Agreed. Here's a new patch that does that, and renames the calls the constants
CTYPE_*

>
> -Sara

-- 
Evan Nemerson
evan@coeus-group.com

---

## #5653 — Hartmut Holzgraefe — 2003-11-21T22:14:08+00:00

URL: https://externals.io/message/5649#5653 · In reply to: #5649

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

---

## #5655 — Evan Nemerson — 2003-11-21T22:25:07+00:00

URL: https://externals.io/message/5649#5655 · In reply to: #5653

> Evan Nemerson wrote:
> > […]
>
> 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
