[php]代码库
<?php
//大小写转换,u 纯大写, l 纯小写, w 每个单词首字母大写, s 每句句首字母首字母大写
function PIPHP_CapsControl($text, $type)
{
switch ($type) {
case 'u':
return strtoupper($text);
break;
case 'l':
return strtolower($text);
break;
case 'w':
$newtext = "";
$words = explode(" ", $text);
foreach ($words as $word) {
$newtext .=ucfirst(strtolower($word)) . " ";
}
return rtrim($newtext);
break;
case 's':
$newtext = "";
$sentences = explode(".", $text);
foreach ($sentences as $sentence)
$newtext .= ucfirst(ltrim(strtolower($sentence))) . ". ";
return rtrim($newtext);
break;
}
}
$text="Thankfully The Government Still hasn't discovered a way of slapping a tax on love, sunshine or air.";
echo PIPHP_CapsControl($text, 'u');
echo "<br>";
echo PIPHP_CapsControl($text, 'l');
echo "<br>";
echo PIPHP_CapsControl($text, 'w');
echo "<br>";
echo PIPHP_CapsControl($text, 's');
?>
初级程序员
by: linux 发表于:2015-11-03 11:36:21 顶(1) | 踩(0) 回复
自己顶
回复评论