Text - to_possessive


/ Published in: PHP
Save to your folder(s)

Transforms string to it's possessive form and return it's original case form.


Copy this code and paste it in your HTML
  1. /*
  2.   * Transform text to show ownership e.g Arvi's, Jess'
  3.   */
  4. public function to_possessive($string)
  5. {
  6. $length = strlen($string);
  7. $last_letter = substr($string, $length-1, $length);
  8.  
  9. $letter_s = ctype_upper($string) ? 'S' : 's';
  10.  
  11. $possessive_form = ($last_letter == $letter_s) ? $string."'" : $string."'".$letter_s;
  12.  
  13. return $possessive_form;
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.