💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
自动翻译程序员英语 1、桌面应用 将中文翻译成程序员英文(驼峰写法等) 2、网页应用 调用翻译接口 字母大写 ucfirst() 把字符串中的首字符转换为大写。 ucwords() 把字符串中每个单词的首字符转换为大写。 strtoupper() 把字符串转换为大写字母。 字母小写 lcfirst() 把字符串的首字符转换为小写。 strtolower() 把字符串转换为小写字母。 字母替换 str\_replace() 替换字符串中的一些字符(对大小写敏感)。 substr\_replace() 把字符串的一部分替换为另一个字符串。 PHP字符串中特殊符号 首字母去除数字 有效长度限制 去重空格 空格替换成\_ \_写法:user\_name/User\_Name/USER\_Name/USER\_NAME 匈牙利命名法:变量名=属性+类型+对象描述 骆驼命名法:userName 帕斯卡命名法:UserName ![](https://img.kancloud.cn/d7/57/d757443c3b8bb18fb0023878809cb70f_1848x353.png) ``` <?php // _写法:user_name/User_Name/USER_Name/USER_NAME // 匈牙利命名法:变量名=属性+类型+对象描述 // 骆驼命名法:userName // 帕斯卡命名法:UserName //匈牙利命名法写不出来啊 // 字母大写 // ucfirst() 把字符串中的首字符转换为大写。 // ucwords() 把字符串中每个单词的首字符转换为大写。 // strtoupper() 把字符串转换为大写字母。 // 字母小写 // lcfirst() 把字符串的首字符转换为小写。 // strtolower() 把字符串转换为小写字母。 // 字母替换 // str_replace() 替换字符串中的一些字符(对大小写敏感)。 // substr_replace() 把字符串的一部分替换为另一个字符串。 // PHP字符串中特殊符号 // 首字母去除数字 // 有效长度限制 // 去重空格 // 空格替换成_ // _写法:user_name/User_Name/USER_Name/USER_NAME // 匈牙利命名法:变量名=属性+类型+对象描述 // 骆驼命名法:userName // 帕斯卡命名法:UserName // $strs //1=帕斯卡命名法,2=_写法,3=骆驼命名法,4、-写法 $str="hello China"; $named=new programmer(1); echo "帕斯卡命名法:".$named->programmer($str)."<br>"; $named=new programmer(2,false,false,true); echo "_写法首字符转换为大写:".$named->programmer($str)."<br>"; $named=new programmer(2,false,true,false); echo "_写法全部小写:".$named->programmer($str)."<br>"; $named=new programmer(2,true,false,false); echo "_写法全部大写:".$named->programmer($str)."<br>"; $named=new programmer(4,false,false,true); echo "-写法首字符转换为大写:".$named->programmer($str)."<br>"; $named=new programmer(4,false,true,false); echo "-写法全部小写:".$named->programmer($str)."<br>"; $named=new programmer(4,true,false,false); echo "-写法全部大写:".$named->programmer($str)."<br>"; $named=new programmer(3); echo "骆驼命名法:".$named->programmer($str)."<br>"; echo "sql 语句"."<br>".$named->create_table("ceshi", "测试表",[["field"=>$named->programmer($str),"name"=>$str]]); class programmer { public $type = "2"; //$this->type:1=帕斯卡命名法,2=_写法,3=骆驼命名法 public $strtoupp = false; //全部大写 public $strtolow = false; //全部小写 。 public $lowe = false; //首字符转换为大写 public function __construct($type=1,$strtoupp= false,$strtolow= false,$lowe= false) { $this->type=$type; $this->strtoupp=$strtoupp; $this->strtolow=$strtolow; $this->lowe=$lowe; } //创建表 public function create_table($tablename, $as,$data=[]) { $sql = "create table " . $tablename; $sql .= " ( id int not null auto_increment,typeid varchar(40) not null comment 'id', "; foreach ($data as $key => $value) { $sql .= " {$value['field']} int(10) not null comment {$value['name']} ,"; } $sql .= " creationtime int(10) not null comment '创建时间', updatetime int(10) not null comment '更新时间' ,"; $sql .= "primary key ( id ))auto_increment = 1 engine=MyISAM default charset=utf8 COMMENT='" . $as . "'"; return $sql; } public function programmer($str) { // // $output =$this->geturl($str); // $str=json_decode('{"type":"ZH_CN2EN","errorCode":0,"elapsedTime":0,"translateResult":[[{"src":"你好中国1602790634","tgt":"Hello China 1602790634"}]]}',true); // echo "<pre>"; // foreach ($str["translateResult"] as $key => $value) { // // code... // } // var_dump($str["translateResult"],$output,2);die; //首字母大写 //false $str = $this->strFilter($str); // var_dump($this->type);die; //帕斯卡命名法 if ($this->type == "1") { // 把字符串转换为小写字母。 $str = strtolower($str) ; //把字符串中每个单词的首字符转换为大写。 $str = ucwords($str); //去除首字母数字 $str = $this->ordstr_replace($str); //去除空格 $str = str_replace(' ', '', $str); // var_dump($str,1);die; return $str; die; } else if ($this->type == "2") { //_写法 //把字符串转换为大写字母。 if ($this->strtoupp) { $str = strtoupper($str); // var_dump("strtoupper"); } else if ($this->strtolow) { //把字符串转换为小写字母。 $str = strtolower($str); // var_dump("strtolower"); } else if ($this->lowe) { // 把字符串转换为小写字母。 $str = strtolower($str) ; //把字符串中每个单词的首字符转换为大写。 $str = ucwords($str); // var_dump("ucwords"); } //去除首字母数字 $str = $this->ordstr_replace($str); //去除空格 $str = str_replace(' ', '_', $str); // var_dump($str);die; return $str; die; } else if ($this->type == "3") { // var_dump(3); //骆驼命名法 // 把字符串转换为小写字母。 $str = strtolower($str) ; $returnstr = ""; //去除首字母数字 $str = $this->ordstr_replace($str); // var_dump($str); $strarr = explode(" ",$str); // var_dump($strarr,1); foreach ($strarr as $key => $value) { if ($key == 0) { $returnstr.= $value; } else { //把字符串中每个单词的首字符转换为大写 $returnstr.= ucfirst($value) ; } // code... } $returnstr = str_replace(' ', '', $returnstr); // var_dump($returnstr); // die; return $returnstr; die; }else if ($this->type == "4") { //_写法 //把字符串转换为大写字母。 if ($this->strtoupp) { $str = strtoupper($str); // var_dump("strtoupper"); } else if ($this->strtolow) { //把字符串转换为小写字母。 $str = strtolower($str); // var_dump("strtolower"); } else if ($this->lowe) { // 把字符串转换为小写字母。 $str = strtolower($str) ; //把字符串中每个单词的首字符转换为大写。 $str = ucwords($str); // var_dump("ucwords"); } //去除首字母数字 $str = $this->ordstr_replace($str); //去除空格 $str = str_replace(' ', '-', $str); // var_dump($str);die; return $str; die; } } //去除首字母数字 public function ordstr_replace($str) { if (ord($str) >= 48 and ord($str) <= 57) { $string = mb_convert_encoding($string, "UTF-8"); $str = str_replace($string, '', $str); } if (ord($str) >= 48 and ord($str) <= 57) { $this->ordstr_replace($str); } return $str; die; } //去除特殊字符 public function strFilter($str) { $str = str_replace('`', '', $str); $str = str_replace('·', '', $str); $str = str_replace('~', '', $str); $str = str_replace('!', '', $str); $str = str_replace('!', '', $str); $str = str_replace('@', '', $str); $str = str_replace('#', '', $str); $str = str_replace('$', '', $str); $str = str_replace('¥', '', $str); $str = str_replace('%', '', $str); $str = str_replace('^', '', $str); $str = str_replace('……', '', $str); $str = str_replace('&', '', $str); $str = str_replace('*', '', $str); $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); $str = str_replace('(', '', $str); $str = str_replace(')', '', $str); $str = str_replace('-', '', $str); $str = str_replace('_', '', $str); $str = str_replace('——', '', $str); $str = str_replace('+', '', $str); $str = str_replace('=', '', $str); $str = str_replace('|', '', $str); $str = str_replace('\\', '', $str); $str = str_replace('[', '', $str); $str = str_replace(']', '', $str); $str = str_replace('【', '', $str); $str = str_replace('】', '', $str); $str = str_replace('{', '', $str); $str = str_replace('}', '', $str); $str = str_replace(';', '', $str); $str = str_replace(';', '', $str); $str = str_replace(':', '', $str); $str = str_replace(':', '', $str); $str = str_replace('\'', '', $str); $str = str_replace('"', '', $str); $str = str_replace('“', '', $str); $str = str_replace('”', '', $str); $str = str_replace(',', '', $str); $str = str_replace(',', '', $str); $str = str_replace('<', '', $str); $str = str_replace('>', '', $str); $str = str_replace('《', '', $str); $str = str_replace('》', '', $str); $str = str_replace('.', '', $str); $str = str_replace('。', '', $str); $str = str_replace('/', '', $str); $str = str_replace('、', '', $str); $str = str_replace('?', '', $str); $str = str_replace('?', '', $str); return trim($str); } } ```