# Posted By

teedy on 07/20/09

# Statistics

Viewed 578 times
Favorited by 0 user(s)

# Convert String to Proper Case

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

Copy this code and paste it in your HTML
`function strProper(\$str) {    \$noUp = array('a','an','of','the','are','at','in');    \$str = trim(\$str);    \$str = strtoupper(\$str[0]) . strtolower(substr(\$str, 1));    for(\$i=1; \$i<strlen(\$str)-1; ++\$i) {        if(\$str[\$i]==' ') {            for(\$j=\$i+1; \$j<strlen(\$str) && \$str[\$j]!=' '; ++\$j); //find next space            \$size = \$j-\$i-1;            \$shortWord = false;            if(\$size<=3) {                \$theWord = substr(\$str,\$i+1,\$size);                for(\$j=0; \$j<count(\$noUp) && !\$shortWord; ++\$j)                    if(\$theWord==\$noUp[\$j])                        \$shortWord = true;            }            if( !\$shortWord )                \$str = substr(\$str, 0, \$i+1) . strtoupper(\$str[\$i+1]) . substr(\$str, \$i+2);        }           \$i+=\$size;    }    return \$str;}\$str = "blah blah";echo strProper(\$str);`