Main Content

Do not SHOUT and do not whisper

Archive - Originally posted on "The Horse's Mouth" - 2008-04-06 02:33:58 - Graham Ellis

"Your Name" says a box on a form on our web page, and visitors who want to sign up duely enter their name. Some of the names are shouted - "GRAHAM ELLIS" - and others are whispered - "graham ellis" when really we would like them all nice and consistent and in regular case - for we're publishing a list of people who have signed up to support a cause.

It's tempting to convert all of the names to lower case and then capitalise the first letter of each word, but that would upset the MacGreggors and daVincis of this world (and Peter Rabbit learned not to get on the wrong side of Mr MacGreggor, I recall).

So ... if the web site visitor uses both upper case and lower case in his name, we'll assume he's got it right. But if he shouts or whispers, we'll convert it as I was originally tempted to do.

Here's the code for that, in PHP.

if (ereg('[A-Z][a-z]',$row[name])) {
  $names .= "$row[name]<br>";
} else {
  $names .= ucwords(strtolower($row[name]))."<br>";
}


And if you want to see some output from that, have a look here; to learn how to do it, have a look at our PHP course pages.