2010年12月28日 星期二

全形半形互轉

自訂:"`"跟"、"互換
/**
 * 全形半形互轉 (輸入 string, F:return 全形|H:return 半形)(BIG5)
 */
function fullForm2halfForm($str, $getType = 'F')
{
    $hForm = array(
            " ",
            "`","1","2","3","4","5","6","7","8","9","0","-","=","\\",
            "~","!","@","#","$","%","^","&","*","(",")","_","+","|",
            "[","]",
            "{","}",
            ";","'",
            ":","\"",
            ",",".","/",
            "<",">","?",
            "a","b","c","d","e","f","g","h","i","j","k","l","m","n",
            "o","p","q","r","s","t","u","v","w","x","y","z",
            "A","B","C","D","E","F","G","H","I","J","K","L","M","N",
            "O","P","Q","R","S","T","U","V","W","X","Y","Z"
        );
    $fForm = array(
            " ",
            "、","1","2","3","4","5","6","7","8","9","0","-","=","\",
            "~","!","@","#","$","%","︿","&","*","(",")","_","+","|",
            "〔","〕",
            "{","}",
            ";","’",
            ":","”",
            ",","‧","/",
            "<",">","?",
            "a","b","c","d","e","f","g","h","i","j","k","l","m","n",
            "o","p","q","r","s","t","u","v","w","x","y","z",
            "A","B","C","D","E","F","G","H","I","J","K","L","M","N",
            "O","P","Q","R","S","T","U","V","W","X","Y","Z"
        );
      
    if ($getType == 'H'){
        $res = str_replace($fForm, $hForm, $str);
    }else{
        $res = str_replace($hForm, $fForm, $str);
    }
    return $res;
}

沒有留言:

張貼留言