JS 代碼轉 PHP 多謝

來源:互聯網
上載者:User
JS 代碼轉 PHP 謝謝
這是是JS的, 我想轉成PHP的,

不懂PHP,謝謝呀

function Getkey(key, sc) {
return (key * 0x0063 + sc) % 0x100
}
function Apple(str) {
var len = str.length / 2;
var i = 1;
var tmp = '';
var key = eval("0x" + str.charAt(0) + str.charAt(1));
while (i < len) {
istr = eval("0x" + str.charAt(i * 2) + str.charAt(i * 2 + 1));
istr = key ^ istr;
if (istr == 2) {
i = i + 1;
key = Getkey(key, istr);
istr = eval("0x" + str.charAt(i * 2) + str.charAt(i * 2 + 1));
istr = key ^ istr;
jstr = istr;
i = i + 1;
key = Getkey(key, istr);
istr = eval("0x" + str.charAt(i * 2) + str.charAt(i * 2 + 1));
istr = key ^ istr;
jstr = jstr * 256 + istr;
tmp = tmp + String.fromCharCode(jstr)
} else tmp = tmp + String.fromCharCode(istr);
i = i + 1;
key = Getkey(key, istr)
}
return tmp
}


------解決方案--------------------
PHP code
echo    Apple("123123");//輸出 "#:" 對嗎?function Getkey($key, $sc){    return    ($key * 0x0063 + $sc) % 0x100;}function Apple($str) {    $len    = mb_strlen($str, "GBK") / 2;    $i    = 1;    $tmp    = '';    $key    = "0x" . $str{0} . $str{1} + 0;    while ($i < $len){        $istr    = "0x" . $str{$i * 2} . $str{$i * 2 + 1} + 0;        $istr = $key ^ $istr;        if ($istr == 2) {            $i        = $i + 1;            $key    = Getkey($key, $istr);            $istr    = "0x" . $str{$i * 2} . $str{$i * 2 + 1} + 0;            $istr    = $key ^ $istr;            $jstr    = $istr;            $i        = $i + 1;            $key    = Getkey($key, $istr);            $istr    = "0x"  . $str{$i * 2} . $str{$i * 2 + 1} + 0;            $istr    = $key ^ $istr;            $jstr    = $jstr * 256 + $istr;            $tmp    = $tmp . chr($jstr);        }        else            $tmp    = $tmp . chr($istr);        $i        = $i + 1;        $key    = Getkey($key, $istr);    }    return $tmp;}
------解決方案--------------------
樓上厲害!
------解決方案--------------------
探討

請教一下,為啥變數,前面都要加個 “$“???
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.