Mega Code Archive

 
Categories / Php / Algorithms
 

Converts a string to Title Case

<?php function titleCase($string) { $len=strlen($string); $i=0; $last= ""; $new= ""; $string=strtoupper($string); while ($i<$len): $char=substr($string,$i,1); if (ereg( "[A-Z]",$last)): $new.=strtolower($char); else: $new.=strtoupper($char); endif; $last=$char; $i++; endwhile; return($new); }; ?>