1. 4

As this post notes, this isn’t perfect, at all. I’d be interested in comments on edge cases that are not properly handled.

  1. 6

    This is dangerous, as you are now potentially telling people their name is not actually their name. You link to the Falsehoods Programmers Believe About Names in the article itself, but I would still like to point out number 12:

    People’s names are case sensitive.

    and number 13:

    People’s names are case insensitive.

    Trying to capitalise names based on what you believe to be correct does not guarantee it actually is correct. Telling someone called “Jack MCK” they are actually called “Jack McK” would be incorrect, but would be the result this script gives you. Serving them a page with their name incorrectly capitalised can be hurtful, especially because they did enter it correctly themselves.

    1. 4

      That’s indeed what’s also said in the article itself. It notes that you might just use the snippet for suggesting a normalized format, letting a user decide which form is correct.

      1. 5

        But why assume it’s incorrect in the first place? You would still be telling them “hey I believe your name is incorrect, do you actually know how to spell your own name?”.

    2. 4

      Oh boy. All thos $variable $names. PHP is so weird if you’re not used to it anymore!

      And yeah, what @bram said. Things like addresses and names should ideally not be touched. The only thing you can maybe get away with is upcasing a last name which I’ve seen some people do, but apart from that, better don’t touch it.

      1. 4

        “Last name” doesn’t always make sense https://www.w3.org/International/questions/qa-personal-names.

        1. 3

          The only thing you can maybe get away with is upcasing a last name which I’ve seen some people do

          Consider the family name “van de Velde”. You really can’t get away with anything because it’s just not how things work outside the English-speaking bubble.

        2. 3

          The only thing I would normalize is whitespace, otherwise, I would store the name as is. If I need to compare it to what the user types at a later time, I would again normalize whitespace, then behind the scenes (not at all visible to the user) fold to a known case (all lower, all upper) both what the user typed and what was saved before comparing.