Posted By

Arvi on 03/31/11


Tagged

text


Versions (?)

Text - to_possessive


 / Published in: PHP
 

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

  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  

You need to login to post a comment.