PHP实现英文标题的正确大写
<?
//实现标题的正确大写
//除了,a,an.the,bu,as if,and,or,nor,of,by之外,其它单词首字母全部大写
function title_upcase($str) {
//将全部单词首字大写
$str = ucwords($str);
//返回一个数组,包含字符串里的所有单词,并且以单词在字符串里的位置作为索引
$wordlist = str_word_count($str,2);
//排除数组里第一个和最后一个元素,因为不需要改变为小写
$wordlist = array_slice($wordlist,1,-1,true);
//如果包含下列单词,则全部小写
foreach ($wordlist as $position => $word) {
switch ($word) {
case 'A':
case 'An':
case 'The':
case 'But':
case 'As':
case 'If':
case 'And':
case 'Or':
case 'Nor':
case 'Of':
case 'By':
$lower = strtolower($word);
$str{$position} = $lower{0};
}
}
return $str;
}
?>
函数描述及例子
<?
$sample = "a study of interesteller galaxies as presented by scientist";
$upcased = title_upcase($sample);
echo $sample; // a study of interesteller galaxies as presented by scientist
echo $upcased; // A Study of Interesteller Galaxies as Presented by Scientist
?>
<?
//实现标题的正确大写
//除了,a,an.the,bu,as if,and,or,nor,of,by之外,其它单词首字母全部大写
function title_upcase($str) {
//将全部单词首字大写
$str = ucwords($str);
//返回一个数组,包含字符串里的所有单词,并且以单词在字符串里的位置作为索引
$wordlist = str_word_count($str,2);
//排除数组里第一个和最后一个元素,因为不需要改变为小写
$wordlist = array_slice($wordlist,1,-1,true);
//如果包含下列单词,则全部小写
foreach ($wordlist as $position => $word) {
switch ($word) {
case 'A':
case 'An':
case 'The':
case 'But':
case 'As':
case 'If':
case 'And':
case 'Or':
case 'Nor':
case 'Of':
case 'By':
$lower = strtolower($word);
$str{$position} = $lower{0};
}
}
return $str;
}
?>
函数描述及例子
<?
$sample = "a study of interesteller galaxies as presented by scientist";
$upcased = title_upcase($sample);
echo $sample; // a study of interesteller galaxies as presented by scientist
echo $upcased; // A Study of Interesteller Galaxies as Presented by Scientist
?>
作者:noel@淘宝网女装新款秋装连衣裙裤子外套上衣_2012时尚女装新款 Ecmall二次开发-PHP技术
地址:http://www.laohucheng.com/post/290/
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!
Tags: php实现英文标题的正确大写 引用(0)
PHP自定义大小验证码函数
用正则加亮关键字
2009
09:39
423
0


