JS code to PHP thanks

Source: Internet
Author: User
JS code to PHP thanks. this is JS. I want to convert it to PHP. I don't know PHP. thank you! functionGetkey (key, SC) {return (key * 0x0063 + SC) % 0x100} functionApple (str) {varlenstr. leng2; vari1; vartmp; var JS code to PHP thanks
This is JavaScript. I want to convert it to PHP,

PHP is not understood. thank you.

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
}


------ Solution --------------------
PHP code
Echo Apple ("123123"); // output "#:" right? 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 ;}
------ Solution --------------------
Upstairs!
------ Solution --------------------
Discussion

For more information, add "$" in front of the variable.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.