Posted By

gbot on 03/10/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gbot


String to title case


 / Published in: PHP
 

  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
Posted By: jimmayes on March 22, 2008

echo ucwords('PHP has a native function for this, use it instead!');

You need to login to post a comment.