[PHP] php大小写转换 →→→→→进入此内容的聊天室

来自 , 2020-12-21, 写在 PHP, 查看 171 次.
URL http://www.code666.cn/view/59a3adea
  1. <?php
  2. //大小写转换,u 纯大写, l 纯小写, w 每个单词首字母大写,  s 每句句首字母首字母大写
  3. function PIPHP_CapsControl($text, $type)
  4. {
  5.         switch ($type) {
  6.                 case 'u':
  7.                         return strtoupper($text);
  8.                         break;
  9.                 case 'l':
  10.                         return strtolower($text);
  11.                         break; 
  12.                 case 'w':
  13.                         $newtext = "";
  14.                         $words = explode(" ", $text);
  15.                         foreach ($words as $word) {
  16.                                 $newtext .=ucfirst(strtolower($word)) . " ";
  17.                         }
  18.                         return rtrim($newtext);
  19.                         break;
  20.                 case 's':
  21.                         $newtext = "";
  22.                         $sentences = explode(".", $text);
  23.                         foreach ($sentences as $sentence)
  24.                                 $newtext .= ucfirst(ltrim(strtolower($sentence))) . ". ";
  25.                         return rtrim($newtext);
  26.                         break;
  27.         }
  28. }
  29. $text="Thankfully The Government Still hasn't discovered a way of slapping a tax on love, sunshine or air.";
  30. echo PIPHP_CapsControl($text, 'u');
  31. echo "<br>";
  32. echo PIPHP_CapsControl($text, 'l');
  33. echo "<br>";
  34. echo PIPHP_CapsControl($text, 'w');
  35. echo "<br>";
  36. echo PIPHP_CapsControl($text, 's');
  37. ?>

回复 "php大小写转换"

这儿你可以回复上面这条便签

captcha