我需要将一些JavaScript calculusion函数转换为PHP。
请帮助用PHP编写这两个循环
JS:
for (a = 0; a < 9; a++)
z = z.replace(new RegExp('\\' + ",-+@/. ;_".charAt(a), 'g'), "NTj2M10AO".charAt(a));
PHP:
$St1 = ",-+@/. ;_";
$St2 = "NTj2M10AO";
for($a=0;$a<9;$a++){
z= preg_replace("\\$St1[$a]" ........ , $St2[$a],$z);
}
和
JS:
var l = 128,
o = (z.length) / 2,
I = '';
for (a = ((k - 1) * l); a < ((k) * l); a++)
I += String.fromCharCode(z.slice(a * 2, (a + 1) * 2));
PHP :
.... ?
感谢您帮助Pros
答案 0 :(得分:1)
我解决了自己
第一循环:
$z="..........."; // a string
$st1=",-+@/. ;_";
$st2="NTj2M10AO";
for($a=0;$a<9;$a++)
$z=str_replace($st1[$a], $st2[$a], $z);
第二个循环:
$l = 128;
$o = (strlen($z)) / 2;
$I = '';
for ($a = (($k - 1) * $l); $a < ($k * $l); $a++)
$I .= chr(substr($z,($a*2),2));
感谢@mawg和其他人