Home > Backend Development > PHP Tutorial > 求可以php编码及其对应js端解码的函数,该如何解决

求可以php编码及其对应js端解码的函数,该如何解决

WBOY
Release: 2016-06-13 11:05:13
Original
986 people have browsed it

求可以php编码及其对应js端解码的函数
js解码的函数需要运行在通过a.php生成的b.html中,加密要求不高,但是不要base64


自己改良过,由于php和js编码不同,造成无法还原



http://topic.csdn.net/u/20121026/21/aa481d57-5268-4377-844a-11e0abf9fdd0.html?seed=358554303&r=80007043#r_80007043
------解决方案--------------------
不知是否符合你的需求

<script><br />function compile(code) {      <br />  var c=String.fromCharCode(code.charCodeAt(0)+code.length);<br />  for(var i=1;i<code.length;i++){<br />    c+=String.fromCharCode(code.charCodeAt(i)+code.charCodeAt(i-1));<br />  }<br />  return escape(c);<br />}<br />document.write(compile('ab中cd'));<br /></script><br /><br /><?php<br />echo compile('ab中cd');<br />function compile($code) {<br />  $code = array_values(unpack('n*', iconv(strlen('汉')==2 ? 'gbk' : 'utf-8', 'ucs-2', $code)));<br />  $c[] = $code[0] + count($code);<br />  for($i=1; $i<count($code); $i++){<br />    $c[] = $code[$i] + $code[$i-1];<br />  }<br />  $r = '';<br />  foreach($c as $v) {<br />    if($v < 256) $r .= urlencode(chr($v));<br />    else $r .= '%u' . strtoupper(dechex($v));<br />  }<br />  return $r;<br />}<br />
Copy after login
GBK环境中结果
f%C3%u4E8F%u4E90%C7 f%C3%u4E8F%u4E90%C7

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template