How to convert JavaScript code into PHP code

Source: Internet
Author: User
Convert JS code to PHP code & lt; script & nbsp; type = "text/javascript" & gt; function & nbsp; rightSide (playerID) & nbsp ;{& nbsp; & nbsp; & nbsp; this JS code is converted to PHP code
 
  
function rightSide(playerID) {
    this.Decrypt2 = function(data) {
        var b = (7 * (data - 6) % 10 + 10) % 10;
        return b.toString();
alert(b.toString());
    }

    this.Decrypt = function(playerID) {
        playerID = playerID.toString();
        var arrID = new Array();
        for (var i = 0; i < playerID.length; i = i + 1) {
            var a = playerID.substr(i, 1);

            switch (a) {
                case "0": arrID.push(this.Decrypt2(0)); break;
                case "4": arrID.push(this.Decrypt2(1)); break;
                case "5": arrID.push(this.Decrypt2(2)); break;
                case "3": arrID.push(this.Decrypt2(3)); break;
                case "6": arrID.push(this.Decrypt2(4)); break;
                case "9": arrID.push(this.Decrypt2(5)); break;
                case "7": arrID.push(this.Decrypt2(6)); break;
                case "1": arrID.push(this.Decrypt2(7)); break;
                case "2": arrID.push(this.Decrypt2(8)); break;
                case "8": arrID.push(this.Decrypt2(9)); break;
            }
        }
        return arrID.join('');
    }
return this.Decrypt(playerID);
}
var idArr = rightSide(5705);


The above JS code can be converted into PHP code. thank you !!! Shared to: function? RightSide (playerID )? {???? This. Decrypt2? =? Functi... 'data-pics = ''>
------ Solution --------------------
Literal translation by php closure (required> = php 5.3)
function rightSide($playerID) {
    $Decrypt2 = function($data) {
        $b = (7 * ($data - 6) % 10 + 10) % 10;
        return $b;
    };
 
    $Decrypt = function($playerID) use ($Decrypt2) {
        $playerID = "$playerID";
        $arrID = Array();
        for ($i = 0; $i < strlen($playerID); $i = $i + 1) {
            $a = substr($playerID, $i, 1);
 
            switch ($a) {
                case "0": $arrID[] = $Decrypt2(0); break;
                case "4": $arrID[] = $Decrypt2(1); break;
                case "5": $arrID[] = $Decrypt2(2); break;
                case "3": $arrID[] = $Decrypt2(3); break;
                case "6": $arrID[] = $Decrypt2(4); break;
                case "9": $arrID[] = $Decrypt2(5); break;
                case "7": $arrID[] = $Decrypt2(6); break;
                case "1": $arrID[] = $Decrypt2(7); break;

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.