String to title case


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



Copy this code and paste it in your HTML
  1. function titleCase($string) {
  2. $len=strlen($string);
  3. $i=0;
  4. $last= "";
  5. $new= "";
  6. $string=strtoupper($string);
  7. while ($i<$len):
  8. $char=substr($string,$i,1);
  9. if (ereg( "[A-Z]",$last)):
  10. $new.=strtolower($char);
  11. else:
  12. $new.=strtoupper($char);
  13. endif;
  14. $last=$char;
  15. $i++;
  16. endwhile;
  17. return($new);
  18. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.