TheSkyOrBust
07-17-2008, 01:23 PM
Being a bit of a Grammar Bully at heart, it annoys me when people don't capitalise their names when submitting a form, so I've come up with a PHP function to solve this problem.
<?php
function correct($i){
// Get first character of string
$ii = $i[0];
// Determine and replace first character
if($ii == 'a'){ $ii=A; }else
if($ii == 'b'){ $ii=B; }else
if($ii == 'c'){ $ii=C; }else
if($ii == 'd'){ $ii=D; }else
if($ii == 'e'){ $ii=E; }else
if($ii == 'f'){ $ii=F; }else
if($ii == 'g'){ $ii=G; }else
if($ii == 'h'){ $ii=H; }else
if($ii == 'i'){ $ii=I; }else
if($ii == 'j'){ $ii=J; }else
if($ii == 'k'){ $ii=K; }else
if($ii == 'l'){ $ii=L; }else
if($ii == 'm'){ $ii=M; }else
if($ii == 'n'){ $ii=N; }else
if($ii == 'o'){ $ii=O; }else
if($ii == 'p'){ $ii=P; }else
if($ii == 'q'){ $ii=Q; }else
if($ii == 'r'){ $ii=R; }else
if($ii == 's'){ $ii=S; }else
if($ii == 't'){ $ii=T; }else
if($ii == 'u'){ $ii=U; }else
if($ii == 'v'){ $ii=V; }else
if($ii == 'w'){ $ii=W; }else
if($ii == 'x'){ $ii=X; }else
if($ii == 'y'){ $ii=Y; }else
if($ii == 'z'){ $ii=Z; }else
{$ii=$ii; } // If not letter, leave as is
// Replace first character of string with new
$i[0] = $ii;
return $i;
}
?>
It works and I'm pleased but, knowing my luck, there is probably an existing function to do this. But I'd like to know what you all think. Criticisms and suggestions will be taken gratefully :cool: .
<?php
function correct($i){
// Get first character of string
$ii = $i[0];
// Determine and replace first character
if($ii == 'a'){ $ii=A; }else
if($ii == 'b'){ $ii=B; }else
if($ii == 'c'){ $ii=C; }else
if($ii == 'd'){ $ii=D; }else
if($ii == 'e'){ $ii=E; }else
if($ii == 'f'){ $ii=F; }else
if($ii == 'g'){ $ii=G; }else
if($ii == 'h'){ $ii=H; }else
if($ii == 'i'){ $ii=I; }else
if($ii == 'j'){ $ii=J; }else
if($ii == 'k'){ $ii=K; }else
if($ii == 'l'){ $ii=L; }else
if($ii == 'm'){ $ii=M; }else
if($ii == 'n'){ $ii=N; }else
if($ii == 'o'){ $ii=O; }else
if($ii == 'p'){ $ii=P; }else
if($ii == 'q'){ $ii=Q; }else
if($ii == 'r'){ $ii=R; }else
if($ii == 's'){ $ii=S; }else
if($ii == 't'){ $ii=T; }else
if($ii == 'u'){ $ii=U; }else
if($ii == 'v'){ $ii=V; }else
if($ii == 'w'){ $ii=W; }else
if($ii == 'x'){ $ii=X; }else
if($ii == 'y'){ $ii=Y; }else
if($ii == 'z'){ $ii=Z; }else
{$ii=$ii; } // If not letter, leave as is
// Replace first character of string with new
$i[0] = $ii;
return $i;
}
?>
It works and I'm pleased but, knowing my luck, there is probably an existing function to do this. But I'd like to know what you all think. Criticisms and suggestions will be taken gratefully :cool: .