function convertStr($str) { $strlength = strlen($str); $cstr = ''; for($i = 0; $i < $strlength; $i++) { $cstr .= "%".strtoupper(base_convert(ord($str{$i}), 10, 16)); } return $cstr; } $s = $_POST['w']; $contents = ($contentscharset = mb_detect_encoding($s, "ASCII, UTF-8, GB2312, GBK")) == "GB2312" ? $s : iconv($contentscharset, "CP936", $s); $w = convertStr($contents);