|
您的位置:学院
>> 编程开发 >>
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);
};
?>
|
|