473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ucfirst

I have abunch of names that I'd like to normalize case-wise. Some are
lowercase (joe jackson), some uppercase (JOE JACKSON), and some correctly
cased (Joe Jackson). ucfirst(strtolower('JOE JACKSON')); works for most
cases, but if there's a name with a hyphen, ie. BILLY-BOB JOHNSON and
jack-bob johnson and Bob-Bob Johnson, they're turned into Billy-bob etc...
The letter after the hyphen should be uppercased as well, not just the ones
after space. Anyone got idea how to do this?

(Then there are names like McGyver or MacCartney and O'Reilly... But that's
okay, we have so few of this kind of names in Finland it doesn't matter.)

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Aug 31 '06 #1
3 1782
I have abunch of names that I'd like to normalize case-wise. Some are
lowercase (joe jackson), some uppercase (JOE JACKSON), and some correctly
cased (Joe Jackson). ucfirst(strtolower('JOE JACKSON')); works for most
cases, but if there's a name with a hyphen, ie. BILLY-BOB JOHNSON and
jack-bob johnson and Bob-Bob Johnson, they're turned into Billy-bob etc...
Lucky you if "your" names do not have accents signs (meaning é, è, ê and
others) ! Otherwise your method wouldn't work, as it would transform
"STEPHANE" into "Stephane" ("STEPHANE" is correct because capital letters do
not take accents, whereas "Stephane" should be written "Stéphane").
The letter after the hyphen should be uppercased as well, not just the
ones
after space. Anyone got idea how to do this?
A dirty trick :
Replace "-" by "- ".
Then do your ucfirst(strtolower($name));
Them replace back "- " by "-".
That should do it !
BLob
Aug 31 '06 #2
"BLob" <bl**@nospam.invalidwrote in message
news:44**********************@news.orange.fr...
>I have abunch of names that I'd like to normalize case-wise. Some are
lowercase (joe jackson), some uppercase (JOE JACKSON), and some correctly
cased (Joe Jackson). ucfirst(strtolower('JOE JACKSON')); works for most
cases, but if there's a name with a hyphen, ie. BILLY-BOB JOHNSON and
jack-bob johnson and Bob-Bob Johnson, they're turned into Billy-bob
etc...

Lucky you if "your" names do not have accents signs (meaning é, è, ê and
others) ! Otherwise your method wouldn't work, as it would transform
"STEPHANE" into "Stephane" ("STEPHANE" is correct because capital letters
do
not take accents, whereas "Stephane" should be written "Stéphane").
>The letter after the hyphen should be uppercased as well, not just the
ones
>after space. Anyone got idea how to do this?

A dirty trick :
Replace "-" by "- ".
Then do your ucfirst(strtolower($name));
Them replace back "- " by "-".
That should do it !

Oh, I never thought of that. How silly, of course that'll work. Good ol'
dirty hacks. :)

Thanks BLob

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Sep 1 '06 #3
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:h_***************@reader1.news.jippii.net...
cased (Joe Jackson). ucfirst(strtolower('JOE JACKSON')); works for most
Whoops... Obviously that was supposed to be ucwords :)

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Sep 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Phil Powell | last post by:
ucfirst({explode('/', $val)}) This produces a parse error expecting ')', but why? I thought this was perfectly valid code structuring in PHP! Any ideas? Phil
3
by: Markus Ernst | last post by:
Hi In a multilanguage application I need the ucfirst() functionality. As this function is not multibyte-compatible I tried a function suggested in the manual: function my_mb_ucfirst($str) {...
1
by: Skeets | last post by:
i have a simple xml file and i use php5.1.2's dom xml to pull out an element's value. i then use use: // $type value all in lower case. $type = ucfirst($type); which doesn't work. ...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
0
The1corrupted
by: The1corrupted | last post by:
Alright, I've set up a chat system that only works half way... I need suggestions on how to make it work better... I'm trying to figure out a way to make $_SESSION viewable to all players by...
4
The1corrupted
by: The1corrupted | last post by:
I know it's a syntax error but I can't quite pin it down and need help doing so. Parse error: parse error, unexpected ';' in C:\postchat.inc.php on line 140 Well, here's the if statement line...
1
The1corrupted
by: The1corrupted | last post by:
<?php session_start(); /*CHAT DISPLAY*/ /* Data for $chatray... 0 = id 1 = who 2 = towho 3 = type 4 = message
1
by: Germaris | last post by:
Hi there! Nowadays trend is to write everything in lowercase. Last Names, First Names, City Names, etc... Maybe the use of computers is one of the reasons to such bad typing. In a form,...
5
by: The Big One | last post by:
8-7-2008 Hello, Our hosting provider has changed his server to PHP5. I have a PHP file that normaly gives the custumor an email, and i get one mail. Now the server has changed i only get my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.