PHP & Possessive Punctuation
Automation is great -- it means less work for the developer, the user, and the server. Everyone's happy, right? Unfortunately computers don't pay attention to detail unless they're told to. One detail we need to program computers to pay attention to is proper apostrophe usage when it comes to possession. For example, "Chris's" is not correct -- when a name ends in "s", no "s" should follow the apostrophe. Coding proper English is simple.
The PHP
function properize($string) {
return $string.'\''.($string[strlen($string) - 1] != 's' ? 's' : '');
}
echo 'Properize: '.properize("Chris"); //returns Chris'
echo 'Properize: '.properize("David"); //returns David's
Just a quick tip I wanted to pass on. Details, details, details!
![CSS vs. JS Animation: Which is Faster?]()
How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps?
This article serves as a point-by-point...
![Conquering Impostor Syndrome]()
Two years ago I documented my struggles with Imposter Syndrome and the response was immense. I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions. I've even caught myself reading the post...
![New York Times-Style Text Selection Widget Using MooTools or jQuery]()
Aaron Newton made a great request to me last week: why not make my MooTools Documentation Bookmarklet function more like the New York Time's text selection widget. NYT's text selection widget listens for text selection and presents the user with a "search" icon...
![Fix Anchor URLs Using MooTools 1.2]()
The administrative control panel I build for my customers features FCKEditor, a powerful WYSIWYG editor that allows the customer to add links, bold text, create ordered lists, and so on. I provide training and documentation to the customers but many times they simply forget to...
Nice func. Will save me some time. Makes me wonder why I didn’t think of this.
@Timothy becoz you are not as intelligent as David and also not a good programmer as him.
Actually, it would be correct: http://www.bartleby.com/141/strunk.html#1
@Charles: In a word….rubbish.
Chris’s is proper English, and Chris’, although an acceptable alternative, is still technically improper and most sources will advise you to use the former. The rule is that any singular possessive noun ends in ‘s, regardless of whether or not the non-possessive form ends in an s.
See the following (or just Google it):
http://owl.english.purdue.edu/owl/resource/621/01/
http://www.grammarbook.com/punctuation/apostro.asp
http://www.englishclub.com/esl-articles/possessive-apostrophe.htm
What about plural possession?
The belongings of the people, or the peoples’ belongings.
Often gibbs of wood have rough edges. Wood gibbs’ edges are often rough.
@Chris the Developer: That’s a bit out of scope for this function.
@Derrick: That goes against everything I’ve ever been taught (and I got A’s in every English class I’ve taken since 5th grade.) I wonder if we teach it different in the US.
Another U.S. professional editor here, and I use primarily the Chicago Manual of Style, which is a standard reference. It says the same: that Chris’s would be correct. See section 7.17 on possessives. The funny part in that section is this: “Since feelings on these matters sometimes run high, users of this manual may wish to modify or add to the exceptions.”
Maybe your teachers all had “high” feelings:)
See http://www.chicagomanualofstyle.org
Just wanted to add that it’s a cool tip, though, and I read your blog every day…
@David Walsh: I don’t know what kind of school you went to… that’s not what I learned. In my book, “Chris’s” is correct. Also, the plural form of “A” is “As”, not “A’s”.
@Chris the Developer: The plural possessive of people is “people’s”. You chose a tricky example since people is an irregular pluralization. However, in general, you are correct that the apostrophe comes after the “s” in plural possessives (e.g. teachers’ belongings).
The rule I was always taught was that if the name/object ended in an “s”, you put ONLY an apostrophe after the word. I’ll be right back — I’m going to go sue my old school district.
David, my school district said the same thing!
This is pretty clever. I’ve only made helper functions for pluralizing a word.
Yea mine taught the same thing. I think it’s more of an understanding that we use that rather than a rule. If ever see a site that uses my name in plurals like this “James’s” I’m going to look at it funny.
Although I’m not sure, I think I was taught the same way as David was. Personally I think “…s’s” looks awkward.
It might not be correct, but when working with programming terms and acronyms I always insert an apostrophe before the S. Sometimes the meaning would change without one.
Uh… wouldn’t it be, like… a lot faster if you manually typed out the apostrophe?
@Jam: Can’t do that in an automated system dogg.
I prefer using substr($string, -1) to get the last character instead of the array, strlen() method you use.
I was taught (public school in New York) that for singular possessive, always add the ‘s.
However, I agree it looks awkward, so I usually use the form with apostrophe only. My own little bit of arrogance.
Yeah, it does look awkward, and that’s why most sources say that it’s acceptable (although not preferable) to use just the apostrophe in those cases. It probably depends on where you’re using it, too. I’d be hesitant to use just the apostrophe on a project for a school, university, or other educational institution :)
You can also use this:
substr ( $string, -1 )
in place of this:
$string[strlen($string) – 1]
which makes for cleaner, more readable code, in my opinion.
Another solution using regxp :
Damn, I just wanted to be cool and say that substr -1 would be way awesomer, but I’ve been beated to it :(
Once again, David Walsh to the rescue with a little snippet.
yet another alternative