资讯专栏INFORMATION COLUMN

自动翻译程序员英语

leoperfect / 2186人阅读

摘要:自动翻译程序员英语桌面应用将中文翻译成程序员英文驼峰写法等网页应用调用翻译接口字母大写把字符串中的首字符转换为大写。

自动翻译程序员英语
1、桌面应用 将中文翻译成程序员英文(驼峰写法等)
2、网页应用

调用翻译接口

字母大写
ucfirst() 把字符串中的首字符转换为大写。
ucwords() 把字符串中每个单词的首字符转换为大写。
strtoupper() 把字符串转换为大写字母。

字母小写
lcfirst() 把字符串的首字符转换为小写。
strtolower() 把字符串转换为小写字母。

字母替换
str_replace() 替换字符串中的一些字符(对大小写敏感)。
substr_replace() 把字符串的一部分替换为另一个字符串。

PHP字符串中特殊符号
首字母去除数字
有效长度限制
去重空格
空格替换成_

_写法:user_name/User_Name/USER_Name/USER_NAME
匈牙利命名法:变量名=属性+类型+对象描述
骆驼命名法:userName
帕斯卡命名法:UserName

</>复制代码

  1. // _写法: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)."
    "
    ;$named=new programmer(2,false,false,true);echo "_写法首字符转换为大写:".$named->programmer($str)."
    "
    ;$named=new programmer(2,false,true,false);echo "_写法全部小写:".$named->programmer($str)."
    "
    ;$named=new programmer(2,true,false,false);echo "_写法全部大写:".$named->programmer($str)."
    "
    ;$named=new programmer(4,false,false,true);echo "-写法首字符转换为大写:".$named->programmer($str)."
    "
    ;$named=new programmer(4,false,true,false);echo "-写法全部小写:".$named->programmer($str)."
    "
    ;$named=new programmer(4,true,false,false);echo "-写法全部大写:".$named->programmer($str)."
    "
    ;$named=new programmer(3);echo "骆驼命名法:".$named->programmer($str)."
    "
    ;echo "sql 语句"."
    "
    .$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;}//创建表
  2. public function create_table($tablename, $as,$data=[]) {
  3. $sql = "create table " . $tablename;
  4. $sql .= " (
  5. id int not null auto_increment,typeid varchar(40) not null comment "id", ";
  6. foreach ($data as $key => $value) {
  7. $sql .= " {$value["field"]} int(10) not null comment {$value["name"]} ,";
  8. }
  9. $sql .= " creationtime int(10) not null comment "创建时间",
  10. updatetime int(10) not null comment "更新时间" ,";
  11. $sql .= "primary key ( id ))auto_increment = 1 engine=MyISAM default charset=utf8 COMMENT="" . $as . """;
  12. return $sql;
  13. }
  14. 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 "

    </>复制代码

    1. "; // 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); }}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/121834.html

相关文章

  • 人工智能时代的降临

    摘要:周二,白宫发布了一份关于人工智能与经济的令人寒心的报告。更重要的是,我们必须超越这种狭隘的思考方式受到人工智能威胁的工作岗位。今年,最瞩目的人工智能与人类的对决就来自。然而,人工智能在年碾压人类的一系列胜利仅仅是个开始。 showImg(https://segmentfault.com/img/remote/1460000008189557?w=1280&h=800); 去年以来关于人...

    animabear 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<