PHP Code $UTF8_UPPER_TO_LOWER Questions

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
itunes66
Registered User
Posts: 169
Joined: Tue Feb 08, 2005 12:28 am

PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by itunes66 »

ok i watch the CVS Updates and i saw the variables $UTF8_UPPER_TO_LOWER and $UTF8_LOWER_TO_UPPER

1. why have both of these variables, you could use

Code: Select all

$UTF8_LOWER_TO_UPPER = array_flip($UTF8_UPPER_TO_LOWER);
2. why have you not used used this because it causes less code to handle (only 1 variable and the other is maintained automatically) and as far as i know array_flip is pretty fast even on very large arrays
2 things i like about you hmm.. ill have to get back to you on that one
agent00shoe

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by agent00shoe »

I haven't looked to see what $UTF8_UPPER_TO_LOWER and $UTF8_LOWER_TO_UPPER actually do, but I don't think array_flip would do what you suggest. Array_flip switches all keys with their associated values.
User avatar
Eelke
Registered User
Posts: 606
Joined: Thu Dec 20, 2001 8:00 am
Location: Bussum, NL
Contact:

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by Eelke »

Well, I'm assuming these are arrays with UTF8 uppercase characters as the keys and the associated UTF8 lowercase characters as the values.

However, I can imagine that to convert ö to uppercase, you actually want to use O, not O with an umlaut on top (in some languages, that's actually considered bad form). I.e., the lower case to upper case table would contain many lower case characters (ö, õ, ô, ó) mapping to the same upper case character (O). Simply reversing that mapping (which is what is being suggested, if I understand correctly) would not get you the correct result.
bad-dj
Posts: 173
Joined: Sat Aug 26, 2006 11:15 am
Location: Australia
Contact:

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by bad-dj »

what is UTF8 mean i do not know and i will not know if i do not ask so i am aksing what is UTF8 ?
itunes66
Registered User
Posts: 169
Joined: Tue Feb 08, 2005 12:28 am

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by itunes66 »

Eelke wrote: Well, I'm assuming these are arrays with UTF8 uppercase characters as the keys and the associated UTF8 lowercase characters as the values.

However, I can imagine that to convert ö to uppercase, you actually want to use O, not O with an umlaut on top (in some languages, that's actually considered bad form). I.e., the lower case to upper case table would contain many lower case characters (ö, õ, ô, ó) mapping to the same upper case character (O). Simply reversing that mapping (which is what is being suggested, if I understand correctly) would not get you the correct result.


that is incorrect.

the way array flip works is like so

take array: array('blabla' => 'blabla2', 'blabla3' => 'blabla4')
Flip
Return Array: array('blabla2' => 'blabla', 'blabla4' => 'blabla3')

and lets reverse that process shall we

take array: array('blabla2' => 'blabla', 'blabla4' => 'blabla3')
Flip
Return Array: array('blabla' => 'blabla2', 'blabla3' => 'blabla4')

So it would work. you can't beat down an active php coder, unless you are from php.net noting that there are/is a bug(s) in php that make hex array fliping not work but, it does
2 things i like about you hmm.. ill have to get back to you on that one
User avatar
th23
Registered User
Posts: 112
Joined: Sat Jul 03, 2004 4:26 pm
Location: Bonn, Germany
Contact:

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by th23 »

Correct me, if I'm wrong, but it is possible to have twice the same value in one array, but not to have twice the same index... So if you flip an the initial array has twice the same value, one index that was there before will get overwritten by the other...

th23
User avatar
Eelke
Registered User
Posts: 606
Joined: Thu Dec 20, 2001 8:00 am
Location: Bussum, NL
Contact:

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by Eelke »

itunes, I didn't imply anything about how the flip function works, in fact what you just described is actually what I understood from your description in the first place. Looks like th23 did understand what I was getting at.

The point was, there may be a many-to-one relationship in the lowercase-to-uppercase mapping, which will cause trouble if you simply reverse the mapping. The flipping of the array will only work correctly if there is an exclusive one-to-one relationship in the mapping.

To put it in your terms:
take array: array('blabla' => 'blabla2', 'blabla3' => 'blabla2')
Flip
Return Array: array('blabla2' => 'blabla', 'blabla2' => 'blabla3')

The return array is not a valid array, AFAIK. Correct me if I'm wrong.

Now, whether this assumed many-to-one relationship is a reality, and is in fact the reason behind the two arrays, I do not know. I was merely presenting a possible explanation.
code reader
Registered User
Posts: 653
Joined: Wed Sep 21, 2005 3:01 pm

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by code reader »

actually, according to php documentation, if there is many-to-one mapping, array_flip will use the last mapping, and all others will be lost, but it is not invalid and is not an error.
the only limitation is that all values must be valid as keys, i.e. of type string or integer. otherwise array_flip should work on any associative array.
specificall in this case,
array_flip($UTF8_UPPER_TO_LOWER) === $UTF8_LOWER_TO_UPPER
so i guess the op has a (admittedly small) point.
itunes66
Registered User
Posts: 169
Joined: Tue Feb 08, 2005 12:28 am

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by itunes66 »

thats correct. i had forgotten about that but still array_flip is a good function to use for this
2 things i like about you hmm.. ill have to get back to you on that one
User avatar
DavidMJ
Registered User
Posts: 932
Joined: Thu Jun 16, 2005 1:14 am
Location: Great Neck, NY

Re: PHP Code $UTF8_UPPER_TO_LOWER Questions

Post by DavidMJ »

The array_flip gives us nothing but another function call, the ten or so lines don't really take up that much space and it is very unlikely we will be changing either array. Why compute something constant when you can precompute it?
Freedom from fear
Post Reply