Re: ctype second opinions
| From: | Brent Cook | Date: | Fri, 19 Jul 2002 16:30:36 +0000 |
| Subject: | Re: ctype second opinions | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-7791@lists.php.net to get a copy of this message | ||
On Fri, 19 Jul 2002, Brad Bulger wrote:
> > > PS - fwiw, i think you're right. ereg('[[:alpha]]','')
> > > returns false.
> > > ctype_alpha('') should do the same thing.
> >
> > Thanks, but I can't continue now that I proved otherwise (unless someone
> > can dispute my proof) :P
>
> you did? did i miss that? i saw that it got made moot by finding out that
> you're not supposed to walk through strings like an array...
>
I had sent to Pierre how I came to the conclusion that the current
behavior is correct, but forgot to CC the list. He probably thinks I'm an
alien now.
Given:
An alpha string is defined a string in which every character is a letter.
Assertion:
An empty string is an alpha string.
Proof:
Take two strings, $a, which is a non-empty alpha string and $b, which is
an empty string:
a = 'Hello' // non-empty alpha string
b = '' // empty string
Assume that b is not an alpha string.
Consider that when strings c and d are appended together, the resulting
string, cd, contains the characters of c and d. If c is an alpha string
and d is not, the cd is cannot be an alpha string because cd contains
characters from d that are not letters.
Now, consider e
e = ab
e contains every character from a and b. By the previous example, if b is
not an alpha string, then e is not an alpha string, since e would then
contain characters that are not letters. But e is an alpha string because
every character in e is a letter. Therefore, b must be an alpha string.
QED
Really, I made too much out of this; I found that ctype_alpha(ord($c))
does what I wanted in the first place :P
Brent