插件2:控制大写锁定键

<?php // Plug-in 2: Caps Control

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$text = "THE SUN WAS SHINING ON THE SEA, SHINING WITH ALL HIS MIGHT: HE DID HIS VERY BEST TO MAKE THE BILLOWS SMOOTH AND BRIGHT - AND THIS WAS ODD, BECAUSE IT WAS THE MIDDLE OF THE NIGHT. THE MOON WAS SHINING SULKILY, BECAUSE SHE THOUGHT THE SUN HAD GOT NO BUSINESS TO BE THERE AFTER THE DAY WAS DONE";

echo PIPHP_CapsControl($text, "u") . "<br />";
echo PIPHP_CapsControl($text, "l") . "<br />";
echo PIPHP_CapsControl($text, "w") . "<br />";
echo PIPHP_CapsControl($text, "s") . "<br />";

function PIPHP_CapsControl($text, $type)
{
   // Plug-in 2: Caps Control
   //
   // This plug-in takes a string variable containing any
   // text and then changes its case according to the
   // argument $style. The arguments required are:
   //
   //    $text: Text to be modified
   //    $style: Must be one of these:
   //       'u' Convert  entirely to upper case (upper)
   //       'l' Convert entirely to lower case (lower)
   //       'w' Capitalize the first letter of each word (word)
   //       's' Capitalize the first letter of each sentence (sentence)
 
   switch($type)
   {
      case "u": return strtoupper($text);

      case "l": return strtolower($text);

      case "w":
         $newtext = "";
         $words   = explode(" ", $text);
         foreach($words as $word)
            $newtext .= ucfirst(strtolower($word)) . " ";
         return rtrim($newtext);

      case "s":
         $newtext   = "";
         $sentences = explode(".", $text);
         foreach($sentences as $sentence)
            $newtext .= ucfirst(ltrim(strtolower($sentence))) . ". ";
         return rtrim($newtext);
   }

   return $text;
}

?>

1.插件说明:

    插件2的第一个参数代表一个字符串变量,第二个参数表示转换方式。根据第二个参数的值对字符串变量进行大小写转换。插件2需要以下参数:

$text: 字符串变量,代表需要转换的文本。

$type: 字符串,代表转换的类型:

    -u 将把所有字母转换为大写;

    -l 将把所有字母转换为小写;

   -w 将把每个单词的第一个字母转换为大写。

    -s 将把每个语句的第一个字母转换为大写。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值