We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

gbot on 03/10/08


Tagged


Versions (?)


Who likes this?

1 person has 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.