日期:2014-05-17 浏览次数:20546 次
<script>GBK环境中结果
function compile(code) {
var c=String.fromCharCode(code.charCodeAt(0)+code.length);
for(var i=1;i<code.length;i++){
c+=String.fromCharCode(code.charCodeAt(i)+code.charCodeAt(i-1));
}
return escape(c);
}
document.write(compile('ab中cd'));
</script>
<?php
echo compile('ab中cd');
function compile($code) {
$code = array_values(unpack('n*', iconv(strlen('汉')==2 ? 'gbk' : 'utf-8', 'ucs-2', $code)));
$c[] = $code[0] + count($code);
for($i=1; $i<count($code); $i++){
$c[] = $code[$i] + $code[$i-1];
}
$r = '';
foreach($c as $v) {
if($v < 256) $r .= urlencode(chr($v));
else $r .= '%u' . strtoupper(dechex($v));
}
return $r;
}