function uni_decode($s) { preg_match_all('/\\&\\#([0-9]{2,5})\\;/', $s, $html_uni); preg_match_all('/[\\\\%]u([0-9a-f]{4})/ie', $s, $js_uni); $source = array_merge($html_uni[0], $js_uni[0]); $js = array(); for ($i = 0; $i < count($js_uni[1]); $i++) { $js[] = hexdec($js_uni[1][$i]); } $utf8 = array_merge($html_uni[1], $js); $code = $s; for ($j = 0; $j < count($utf8); $j++) { $code = str_replace($source[$j], unicode2utf8($utf8[$j]), $code); } return $code; //$s;//preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))", $s); }
function unescape($source) { $target = ""; for ($pos = 0; $pos < strlen($source);) { $char = substr($source, $pos++, 1); if ($char == '%') { $next = substr($source, $pos++, 1); if ($next == 'u') { $codestr = substr($source, $pos, 4); $unicode = hexdec($codestr); $target .= unicode2utf8($unicode); $pos += 4; } else { $target .= $char; $target .= $next; } } else { $target .= $char; } } return $target; }
<?php header("Content-Type:text/html; charset=utf-8"); $input = ""; if (isset($_POST['sentence'])) { $input = $_POST['sentence']; } $UTF8sentence = unicode2utf8($input); $BIG5sentence = iconv("UTF-8", "big5", $UTF8sentence); // $sentence = iconv("UTF-8", "big5", $input); $command = "directCut.py \"{$BIG5sentence}\""; // echo $command. '<br/>'; $output = shell_exec($command); echo $output; function unicode2utf8($str) { if (!$str) { return $str; } $decode = json_decode($str); if ($decode) { return $decode; } $str = '["' . $str . '"]'; $decode = json_decode($str); if (count($decode) == 1) { return $decode[0]; } return $str; }
<?php /** * unicode2utf8 */ if (isset($_POST['btn1']) && $_POST["btn1"]) { $str = trim($_POST["str"]); $ret = unicode2utf8($str); } function unicode2utf8($str) { if (!$str) { return $str; } $decode = json_decode($str); if ($decode) { return $decode; } $str = '["' . $str . '"]'; $decode = json_decode($str); if (count($decode) == 1) { return $decode[0]; } return $str; } ?> <FORM METHOD=POST ACTION=""> 结果: <TEXTAREA NAME="str" ROWS="14" COLS="80"><?php echo isset($str) ? $str : '';
/** * returns the html * if $em_membership is set * then this membership is emphasized * @param $em_membership membership to be emphasized * @returns html of the People block */ function getPeopleHTML($em_membership = -1) { $html = ''; // html to return $p = $this->getPeople(); if (!$p) { return ''; } else { foreach ($p as $pu) { $pname = unicode2utf8($pu['name']); _filter_res_var($pname); if ($pu['id'] == $em_membership) { $html .= "<div style=\"margin-bottom: 5px;\">"; $html .= "<img src=\"{$pu['icon']}\" border=\"0\" width=\"16\" height=\"16\" align=\"absbottom\" /> "; // I love my server $html .= "<a href=\"javascript:void()\" rel=\"me\">"; $html .= "<b>{$pname}</b>"; // emphasized $html .= "</a></div>\n"; } else { $html .= "<div style=\"margin-bottom: 5px;\">"; $html .= "<img src=\"{$pu['icon']}\" border=\"0\" width=\"16\" height=\"16\" align=\"absbottom\" /> "; $html .= "<a href=\"javascript:void(people_show({$pu['id']},'{$pu['member_username']}'))\" rel=\"contact\">"; $html .= $pname; $html .= "</a></div>\n"; } } /** * no, doesn't work in getExtraHead() */ $html .= <<<EOS <script type="text/javascript" src="http://grou.ps/includes/wz_dragdrop.js"></script> <script type="text/javascript"> <!-- function crop_preloader() { SET_DHTML('theCrop'); } crop_preloader(); function my_DragFunc() { var z = xHeight('theImage')<=xWidth('theImage')?xHeight('theImage'):xWidth('theImage'); dd.elements.theCrop.maxoffr = xWidth('theImage') - dd.elements.theCrop.w; dd.elements.theCrop.maxoffb = xHeight('theImage') - dd.elements.theCrop.h; dd.elements.theCrop.maxoffl = 0; dd.elements.theCrop.maxofft = 0; dd.elements.theCrop.minw = 80; dd.elements.theCrop.minh = 80; dd.elements.theCrop.maxw = (xWidth('theImage') + xPageX('theImage')) - dd.elements.theCrop.x; dd.elements.theCrop.maxh = (xHeight('theImage') + xPageY('theImage')) - dd.elements.theCrop.y; } function my_ResizeFunc() { var z = xHeight('theImage')<=xWidth('theImage')?xHeight('theImage'):xWidth('theImage'); dd.elements.theCrop.maxoffr = xWidth('theImage') - dd.elements.theCrop.w; dd.elements.theCrop.maxoffb = xHeight('theImage') - dd.elements.theCrop.h; dd.elements.theCrop.maxoffl = 0; dd.elements.theCrop.maxofft = 0; dd.elements.theCrop.minw = 80; dd.elements.theCrop.minh = 80; dd.elements.theCrop.maxw = (xWidth('theImage') + xPageX('theImage')) - dd.elements.theCrop.x; dd.elements.theCrop.maxh = (xHeight('theImage') + xPageY('theImage')) - dd.elements.theCrop.y; } //--> </script> EOS; return $html; } }
} return $str; } $type = $argv[1]; $query = $argv[3]; $code_type = $argv[2]; if ($type == 'encode') { if ($code_type == 'url') { echo urlencode($query); } elseif ($code_type == 'utf8') { echo utf8_encode($query); } elseif ($code_type == 'html') { echo htmlentities($query); } elseif ($code_type == 'base64') { echo base64_encode($query); } } if ($type == 'decode') { if ($code_type == 'url') { echo urldecode($query); } elseif ($code_type == 'utf8') { echo utf8_decode($query); } elseif ($code_type == 'html') { echo html_entity_decode($query); } elseif ($code_type == 'base64') { echo base64_decode($query); } elseif ($code_type == 'json') { print_r(json_encode(unicode2utf8($query), JSON_UNESCAPED_UNICODE)); } } echo "\n";
} else { if ($mode == "thought") { echo $json[$mode]; } else { echo $json[$mode]; } } $imgurl = ROOT_WEB_URL . "wechat/pics/" . $mode . "1.jpg"; $link = ROOT_WEB_URL . 'getstuff/stuff/' . $_GET["date"] . '_' . $mode . '.html'; echo '</body><script type="text/javascript" language="javascript" src="/include/googleanalysis.js"></script>' . getWechatShareScript($link, $title, $imgurl) . '</html>'; } else { echo $ret; } die; } $trimedUtf8 = array(unicode2utf8("\\u0014")); /* 错误码定义 1 没有日期参数或日期参数不正确 2 未获取到数据 3 连接数据库失败 */ //http://mhchina.a24.cc/api/v1/getstuff/ header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-type: text/html; charset=utf-8"); require_once "chinese_conversion/convert.php"; $isjson = 1; $errorcode = 1; $mode = ""; if (array_key_exists("type", $_GET)) {