一個php編碼轉換類的問題

來源:互聯網
上載者:User
這是一段實現亂碼自動轉換為中文的自訂類changcode
class changecode{
private $str;
private $input;
private $output;
function __construct($input="",$output='gb2312'){
$this->input = $input;
$this->output = $output;
}
protected function chgcode($str){
if($this->input != ''){
$this->str = iconv($input,$output,$str);
}else{
$this->str = mb_convert_encoding($str,$output);
}
}
function getStr($str){
$this->chgcode($str);
return $this->str;
}
function setInput($input){
$this->input = $input;
}
function setOutput($output){
$this->output = $output;
}
function getInput(){
return $this->input;
}
function getOutput(){
return $this->output;
}
}

?>
我的問題是怎麼調用這段代碼實現轉換為中文貌似不管用
$str="??";//這是繁體字
$test=new changecode();
echo $test -> getStr($str);

我想知道為什麼還是輸出繁體字


回複討論(解決方案)

是不是因為setInput也要指定BIG5呢?

好像也不管用啊,求助,線上等

你這個程式只是轉編碼,與簡繁沒有關係。
簡繁轉換是需要有對照表的。

貼出的程式轉碼而已,繁體轉簡體參照
http://download.csdn.net/detail/very68com/5895009

你需要有個簡繁對應表,例如gb2big.map

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.