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!
![9 More Mind-Blowing WebGL Demos]()
With Firefox OS, asm.js, and the push for browser performance improvements, canvas and WebGL technologies are opening a world of possibilities. I featured 9 Mind-Blowing Canvas Demos and then took it up a level with 9 Mind-Blowing WebGL Demos, but I want to outdo...
![An Interview with Eric Meyer]()
Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it?
At first blush, it was the simplicity of it as compared to the table-and-spacer...
![CSS content and attr]()
CSS is becoming more and more powerful but in the sense that it allows us to do the little things easily. There have been larger features added like transitions, animations, and transforms, but one feature that goes under the radar is generated content. You saw a...
![Create a CSS Flipping Animation]()
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
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