python字符串片段的PHP等价物
我不熟悉python,需要将python脚本转换为php。我已经完成了大部分工作,但我无法将这些字符串转换为phppython字符串片段的PHP等价物,php,python,Php,Python,我不熟悉python,需要将python脚本转换为php。我已经完成了大部分工作,但我无法将这些字符串转换为php temp=int(encodedurl[strlen-4:strlen],10) encodedurl=encodedurl[0:strlen-4] 下面是python脚本: def decodeurl(encodedurl): tempp9 ="" tempp4="1071045098811121041051095255102103119" strlen
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
def decodeurl(encodedurl):
tempp9=“”
temp4=“1071045098811121041051095255102103119”
strlen=len(encodedurl)
temp5=int(encodedurl[strlen-4:strlen],10)
encodedurl=encodedurl[0:strlen-4]
strlen=len(encodedurl)
temp6=“”
temp7=0
temp8=0
而temp8
下面是我的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;
}
函数解码($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;
而($temp8<$strlen)
$temp7=$temp7+2;
$temp9=$encodedurl[$temp8:$temp8+4];
$temp9i=intval($temp9,16);
$partlen=($temp8/4)%strlen($temp4));
$partint=intval($temp4[$partlen:$partlen+1]);
$temp9i=(($temp9i-$temp5)-$partint)-($temp7*$temp7))-16)/3;
$temp9=chr($temp9i);
$temp6=$temp6+$temp9;
$temp8=$temp8+4;
返回$6;
}
有人能告诉我什么是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;
}
函数解码($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;
而($temp8<$strlen){
$temp7=$temp7+2;
$temp9=substr($encodedurl,$temp8,4);
$temp9i=intval($temp9,16);
$partlen=($temp8/4)%strlen($temp4));
$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();
返回$6;
}
您在这行有问题
$temp5=intval($encodedurl[$strlen-4],10);
$encodedurl=$encodedurl[0:$strlen-4];
因为php不将字符串视为数组,所以您需要使用类似于的函数在Python上的任何序列上进行切片,不仅是在字符串上,而且在应用于字符串时,这:
s[a:b]
同:
substr(s, a, b-a)
对于0Python的函数与PHP的函数非常相似
因此,您的Python代码:
temp=int(encodedurl[strlen-4:strlen],10)
encodedurl=encodedurl[0:strlen-4]
转换为以下PHP代码:
$temp=intval(substr($encodedurl, -4));
$encodedurl=substr($encodedurl, 0, -4);
谢谢你的解释。我已经根据我的理解更新了代码,但结果并不是我所期望的。你得到了什么?用示例输入和预期输出更新你的问题也会很有用。谢谢,我实际上没有输入。我试图从python脚本使用的数据库中解码字符串。我将在下面发布输出,请检查我是否为$temp9和$partint设置了正确的翻译,因为$partlen从未在我更新的函数中使用过…这里是输出字符串。。。tmurl*401717B4C50D526FB6A6CC19150C106E40B6345AF53338CB91FF51EAB441CFA94CFF5FC856D8D476D04F8088CF433316CA4955C2F7A7C6ADBA07D3A008280CF514B31CD86CACF571B657F0C67F8727991C73DB2B423F5DC5EE5F14E815E38I计算出并更新了函数。再次感谢