自動翻譯程序員英語
1、桌面應用 將中文翻譯成程序員英文(駝峰寫法等)
2、網頁應用
調用翻譯接口
字母大寫
ucfirst() 把字符串中的首字符轉換為大寫。
ucwords() 把字符串中每個單詞的首字符轉換為大寫。
strtoupper() 把字符串轉換為大寫字母。
字母小寫
lcfirst() 把字符串的首字符轉換為小寫。
strtolower() 把字符串轉換為小寫字母。
字母替換
str\_replace() 替換字符串中的一些字符(對大小寫敏感)。
substr\_replace() 把字符串的一部分替換為另一個字符串。
PHP字符串中特殊符號
首字母去除數字
有效長度限制
去重空格
空格替換成\_
\_寫法:user\_name/User\_Name/USER\_Name/USER\_NAME
匈牙利命名法:變量名=屬性+類型+對象描述
駱駝命名法:userName
帕斯卡命名法:UserName

```
<?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);
}
}
```