我不熟悉python,需要將python腳本轉換爲php。我已經做了大部分,但我不能讓這些字符串轉換到PHPpython字符串切片的PHP等效項目
temp=int(encodedurl[strlen-4:strlen],10)
encodedurl=encodedurl[0:strlen-4]
下面是python腳本:
def decodeurl(encodedurl):
tempp9 =""
tempp4="1071045098811121041051095255102103119"
strlen = len(encodedurl)
temp5=int(encodedurl[strlen-4:strlen],10)
encodedurl=encodedurl[0:strlen-4]
strlen = len(encodedurl)
temp6=""
temp7=0
temp8=0
while temp8 < strlen:
temp7=temp7+2
temp9=encodedurl[temp8:temp8+4]
temp9i=int(temp9,16)
partlen = ((temp8/4) % len(tempp4))
partint=int(tempp4[partlen:partlen+1])
temp9i=((((temp9i - temp5) - partint) - (temp7 * temp7)) -16)/3
temp9=chr(temp9i)
temp6=temp6+temp9
temp8=temp8+4
return temp6
這裏是我的PHP轉換:
function decode($encodedurl)
{
$tempp9 ="";
$tempp4="1071045098811121041051095255102103119";
$strlen = strlen($encodedurl);
$temp5=intval($encodedurl[$strlen-4],10);
$encodedurl=$encodedurl[0:$strlen-4];
echo $encodedurl; die();
$strlen = strlen($encodedurl);
$temp6="";
$temp7=0;
$temp8=0;
while ($temp8 < $strlen)
$temp7=$temp7+2;
$temp9=$encodedurl[$temp8:$temp8+4];
$temp9i=intval($temp9,16);
$partlen = (($temp8/4) % strlen($tempp4));
$partint=intval($tempp4[$partlen:$partlen+1]);
$temp9i=(((($temp9i - $temp5) - $partint) - ($temp7 * $temp7)) -16)/3;
$temp9=chr($temp9i);
$temp6=$temp6+$temp9;
$temp8=$temp8+4;
return $temp6;
}
請問有人能告訴我什麼是相當於在PHP?
更新PHP函數:
function decode($encodedurl)
{
$tempp9 ="";
$tempp4="1071045098811121041051095255102103119";
$strlen = strlen($encodedurl);
$temp5=intval(substr($encodedurl, -4));
$encodedurl=substr($encodedurl, 0, -4);
$strlen = strlen($encodedurl);
$temp6="";
$temp7=0;
$temp8=0;
while ($temp8 < $strlen){
$temp7=$temp7+2;
$temp9=substr($encodedurl, $temp8, 4);
$temp9i=intval($temp9,16);
$partlen = (($temp8/4) % strlen($tempp4));
$partint=substr($tempp4,$partlen,1);
$temp9i=(((($temp9i - $temp5) - $partint) - ($temp7 * $temp7)) -16)/3;
$temp9=chr($temp9i);
$temp6=$temp6.$temp9;
$temp8=$temp8+4;
}
echo $temp6; die();
return $temp6;
}
謝謝你的解釋。我已經更新了我所瞭解的代碼,但結果並不是我期待的。 – user969068
你在做什麼? –
用示例輸入和預期輸出來更新您的問題也是有用的 –