Forum Moderators: coopster

Message Too Old, No Replies

Mixed Case Strings-S

         

grandpa

12:49 am on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Pardon if this has been asked before (I believe it has..)

I'm processing strings that a person could type in JUsT aBOut any CasE format. Now I can figure out what should and should not be Upper or Lower case, but I'm having trouble with some bits. An example would be this apartment number:

JOHN DOE
123 ELM ST APT-2A
gets converted to:
John Doe
123 Elm St Apt-2a

The apartment number should be 2A. There are some other examples of this sort of string manipulation:

Couer D'Alene is converted to Couer D'alene

How does one go about handling these types of strings? I didn't see anything specific in PHP functions.

jollymcfats

1:41 am on Jan 28, 2005 (gmt 0)

10+ Year Member



How about something along these lines?

function reCase($string) {
return preg_replace('/\b(\d*)([a-z])/e', '"$1".ucfirst("$2")', strtolower($string));
}

Without the Apt-2A case, you'd be able to get away with just the \b.

grandpa

4:29 am on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank Jolly

That seems like it will handle most situations. I'm only applying it to output screens right now, then I can tweak as needed as I look at some of my data a little closer. When I'm happy I'll add it to the processing side. Life would be easier if my cart escaped everything and normalized my data before sending it to me...