3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function encode($string,$key) { $key = sha1($key); $strLen = strlen($string); $keyLen = strlen($key); for ($i = 0; $i < $strLen; $i++) { $ordStr = ord(substr($string,$i,1)); if ($j == $keyLen) { $j = 0; } $ordKey = ord(substr($key,$j,1)); $j++; $hash .= strrev(base_convert(dechex($ordStr + $ordKey),16,36)); } return $hash; } function decode($string,$key) { $key = sha1($key); $strLen = strlen($string); $keyLen = strlen($key); for ($i = 0; $i < $strLen; $i+=2) { $ordStr = hexdec(base_convert(strrev(substr($string,$i,2)),36,16)); if ($j == $keyLen) { $j = 0; } $ordKey = ord(substr($key,$j,1)); $j++; $hash .= chr($ordStr - $ordKey); } return $hash; } echo encode("i:1:1",3029); echo decode(encode("i:1:1"),3029); ?>
Output for 7.1.0
Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 p533q273t2 Fatal error: Uncaught ArgumentCountError: Too few arguments to function encode(), 1 passed in /in/7LWKW on line 30 and exactly 2 expected in /in/7LWKW:2 Stack trace: #0 /in/7LWKW(30): encode('i:1:1') #1 {main} thrown in /in/7LWKW on line 2
Process exited with code 255.
Output for 5.1.0 - 7.0.14
Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 p533q273t2 Warning: Missing argument 2 for encode(), called in /in/7LWKW on line 30 and defined in /in/7LWKW on line 2 Notice: Undefined variable: key in /in/7LWKW on line 3 Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 Notice: Undefined variable: j in /in/7LWKW on line 22 Notice: Undefined variable: j in /in/7LWKW on line 23 Notice: Undefined variable: j in /in/7LWKW on line 24 Notice: Undefined variable: hash in /in/7LWKW on line 25 if3:^
Output for 5.0.4 - 5.0.5
Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 p533q273t2 Warning: Missing argument 2 for encode() in /in/7LWKW on line 2 Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 Notice: Undefined variable: j in /in/7LWKW on line 22 Notice: Undefined variable: j in /in/7LWKW on line 23 Notice: Undefined variable: j in /in/7LWKW on line 24 Notice: Undefined variable: hash in /in/7LWKW on line 25 if3:^
Output for 4.3.0 - 5.0.3
Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 p533q273t2 Warning: Missing argument 2 for encode() in /in/7LWKW on line 2 Notice: Undefined variable: j in /in/7LWKW on line 8 Notice: Undefined variable: j in /in/7LWKW on line 9 Notice: Undefined variable: j in /in/7LWKW on line 10 Notice: Undefined variable: hash in /in/7LWKW on line 11 Notice: Undefined variable: j in /in/7LWKW on line 22 Notice: Undefined variable: j in /in/7LWKW on line 23 Notice: Undefined variable: j in /in/7LWKW on line 24 Notice: Undefined variable: hash in /in/7LWKW on line 25 if3:^