這是一段實現亂碼自動轉換為中文的自訂類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