\n";
$str0 = "較";
$str1 = mb_convert_encoding($str0, 'cp1252', 'UTF-8');
$str2 = mb_convert_encoding($str1, 'cp1252', 'UTF-8');
print "str0 = $str0, str1 = $str1, str2 = $str2
\n"; $str0 = "言"; //$str1 = mb_convert_encoding($str0, 'UTF-8', 'Windows-1252'); //$str2 = mb_convert_encoding($str1, 'UTF-8', 'Windows-1252'); $str1 = mb_convert_encoding($str0, 'cp1252', 'UTF-8'); $str2 = mb_convert_encoding($str1, 'cp1252', 'UTF-8'); print "str0 = $str0, str1 = $str1, str2 = $str2
\n"; $url = '%C3%A5%E2%80%A1%C2%B1'; $decoded = urldecode($url); $correct = mb_convert_encoding($decoded, 'UTF-8', 'GB2312'); echo $correct; // 輸出 "凱" //drupal_exit(); $array = array('UTF-8', 'Windows-1252', 'ISO-8859-2', 'GBK', 'BIG-5', 'Windows-1251', 'ISO-8859-1','Unicode','CP1252'); //$array = mb_list_encodings(); $encodedString = '%C2%B1%C3%9C%C3%88%C3%BD%C3%89%C3%A1'; $encodedString = '%C3%83%C2%A5%C3%8B%C5%93%C3%82%C2%BF'; $result = '嘿'; //$encodedString = '😃'; $decodedString = urldecode($encodedString); $mb_detect_encoding = mb_detect_encoding($decodedString, $array); echo "mb_detect_encoding = $mb_detect_encoding
encodedString = $encodedString
"; // 輸出:±Ã echo "decodedString = $decodedString
"; // 輸出:±Ã /* $from_value = 'ISO-8859-1';//'GBK';//'ISO-8859-1';//'GBK'; $to_value = 'UTF-8';//'ISO-8859-1';//'GBK';//'UTF-8'; $value_3 = 'UTF-8'; $OutputString = mb_convert_encoding($decodedString, $to_value, $from_value); $OutputString = mb_convert_encoding($OutputString, $value_3, $to_value); //$OutputString = iconv($from_value, $to_value, $decodedString); echo "from_value = $from_value, to_value = $to_value, OutputString = $OutputString, " . urlencode($OutputString) . "
"; $str0 = $decodedString;//'²»ÖªµÀÕâÑùµÄÖ÷»ú¡£'; $str1 = iconv("UTF-8", "ISO-8859-1", $str0); $str2 = iconv("GB18030", "UTF-8", $str1); echo "str0 = $str0, str1 = $str1, str2 = $str2
"; $str4 = iconv("GBK", "ISO-8859-1", $str0); echo "str4 = $str4
"; */ /* foreach ($array as $from_value) { print "
from_value = $from_value
"; //echo "
\n"; $str0 = "言"; //$str1 = mb_convert_encoding($str0, 'UTF-8', 'Windows-1252'); //$str2 = mb_convert_encoding($str1, 'UTF-8', 'Windows-1252'); $str1 = mb_convert_encoding($str0, 'cp1252', 'UTF-8'); $str2 = mb_convert_encoding($str1, 'cp1252', 'UTF-8'); print "str0 = $str0, str1 = $str1, str2 = $str2
\n"; $url = '%C3%A5%E2%80%A1%C2%B1'; $decoded = urldecode($url); $correct = mb_convert_encoding($decoded, 'UTF-8', 'GB2312'); echo $correct; // 輸出 "凱" //drupal_exit(); $array = array('UTF-8', 'Windows-1252', 'ISO-8859-2', 'GBK', 'BIG-5', 'Windows-1251', 'ISO-8859-1','Unicode','CP1252'); //$array = mb_list_encodings(); $encodedString = '%C2%B1%C3%9C%C3%88%C3%BD%C3%89%C3%A1'; $encodedString = '%C3%83%C2%A5%C3%8B%C5%93%C3%82%C2%BF'; $result = '嘿'; //$encodedString = '😃'; $decodedString = urldecode($encodedString); $mb_detect_encoding = mb_detect_encoding($decodedString, $array); echo "mb_detect_encoding = $mb_detect_encoding
encodedString = $encodedString
"; // 輸出:±Ã echo "decodedString = $decodedString
"; // 輸出:±Ã /* $from_value = 'ISO-8859-1';//'GBK';//'ISO-8859-1';//'GBK'; $to_value = 'UTF-8';//'ISO-8859-1';//'GBK';//'UTF-8'; $value_3 = 'UTF-8'; $OutputString = mb_convert_encoding($decodedString, $to_value, $from_value); $OutputString = mb_convert_encoding($OutputString, $value_3, $to_value); //$OutputString = iconv($from_value, $to_value, $decodedString); echo "from_value = $from_value, to_value = $to_value, OutputString = $OutputString, " . urlencode($OutputString) . "
"; $str0 = $decodedString;//'²»ÖªµÀÕâÑùµÄÖ÷»ú¡£'; $str1 = iconv("UTF-8", "ISO-8859-1", $str0); $str2 = iconv("GB18030", "UTF-8", $str1); echo "str0 = $str0, str1 = $str1, str2 = $str2
"; $str4 = iconv("GBK", "ISO-8859-1", $str0); echo "str4 = $str4
"; */ /* foreach ($array as $from_value) { print "
from_value = $from_value
"; //echo "
- ";
foreach($array as $to_value) {
//print "
- to_value = $to_value";
//$OutputString = iconv($from_value, $to_value, $decodedString);
$OutputString = mb_convert_encoding($decodedString, $to_value, $from_value);
//echo "
- ";
foreach($array as $to_3) {
$OutputString = mb_convert_encoding($OutputString, $to_3, $from_value);
foreach($array as $to_4) {
$OutputString = mb_convert_encoding($OutputString, $to_4, $from_value);
//print "
- to_3 = $to_3,";
if ($OutputString == $result) {
print "
from_value = $from_value
"; print "to_value = $to_value,"; print "to_3 = $to_3,to_4 = $to_4,"; echo "OutputString = $OutputString, " . urlencode($OutputString); // 輸出:±你 } //print " \n";
}
}
//echo "
";
}
//echo " - to_3 = $to_3,";
if ($OutputString == $result) {
print "
my留言
my留言