这是将一句英文的每个单词的第一个字母转换成大写的例子。
[code]
<?php
function titleCase($string) {
global $new;
$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);
};
//以下是测试:
$k="hi,i am TEAMAN,nice to meet of all of you";
titlecase($k);
echo $new;
//结果将返回:Hi,I Am Teaman,Nice To Meet All Of You
?>
[/code]