2015-11-06 141 views
-5

任何人都可以幫我把這個轉換成PHP嗎?如何將JavaScript轉換爲PHP代碼

var encoded = ''; 
var resnumber = 0; 

for (v = 1; v <= evnumber; v++) { 
    var indcode = v + 'code'; 
    var valcode = document.getElementById(indcode).value; 

    valcode = valcode.trim(); 

    var indname = v + 'name'; 
    var valname = document.getElementById(indname).value; 
    valname = valname.trim(); 
    var indleague = v + 'league'; 
    var valleague = document.getElementById(indleague).value; 
    valleague = valleague.trim(); 

    var inddate = v + 'date'; 
    var valdate = document.getElementById(inddate).value; 

    valdate = valdate.trim(); 
    var indtime = v + 'time'; 
    var valtime = document.getElementById(indtime).value; 
    valtime = valtime.trim(); 
    var indnumb = v + 'numb'; 
    var valnumb = document.getElementById(indnumb).value; 
    valnumb = valnumb.trim(); 
    valnumb = parseInt(valnumb); 
    encoded = encoded + valcode + '<e>' + valname + '<e>' + valleague + '<e>' + valdate + '<e>' + valtime + '<e>' + valnumb + '<e>'; 
    for (w = 0; w < valnumb; w++) { 
     var indtype = v + 'signe|' + w; 
     var valtype = document.getElementById(indtype).value; 
     valtype = valtype.trim(); 
     var indodd = v + 'odd|' + w; 
     var valodd = document.getElementById(indodd).value; 

     valodd = valodd.trim(); 
     encoded = encoded + valtype + '<e>' + valodd + '<e>'; 
     resnumber++; 
    } 

    encoded = encoded + '|'; 
} 


encoded = encoded + '<results>'; 

for (t = 0; t < resnumber; t++) { 
    encoded = encoded + '<res>'; 
} 
+4

我投票關閉這一問題作爲題外話,因爲堆棧是不是免費的代碼轉換服務。 –

+0

JavaScript在客戶端(瀏覽器)上運行。 PHP在服務器上運行。他們不太適合取代彼此的功能。 –

+1

Downvote明顯的「請爲我做我的作業」。 – metaColin

回答

1

你不能簡單地將它轉換爲PHP,因爲它在處理與DOM元素的值。 PHP和JavaScript之間的語法非常相似,從你的例子清單,我可以告訴你的同行:

var encoded = ''; 
$encoded = ''; 

var resnumber = 0; 
$resnumber = 0; 

for(v=1;v<=evnumber;v++) { 
for($v=1; $v<=$evnumber; $v++) { 

var indcode = v + 'code'; 
$indcode = $v + 'code'; 

var valcode = document.getElementById(indcode).value; 
// This is an example of something you can't do with PHP, because it doesnt have access to the document unless your parsing it with DOMDocument or something.