3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRandomString($n) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ=+/'; $randomString = ''; for ($i = 0; $i < $n; $i++) { $index = rand(0, strlen($characters) - 1); $randomString .= $characters[$index]; } return $randomString; } foreach (['foo', 'bar', getRandomString(100), getRandomString(2000), '', getRandomString(2000)] as $data) { $hash = base64_encode(hash('sha256', $data, TRUE)); print base64_encode(hash('sha256', $data, TRUE)) . ' : '; // Modify the hash so it's safe to use in URLs. $hashed = str_replace(['+', '/', '='], ['-', '_', ''], $hash); print $hashed . ' : '; print strlen($hashed) . PHP_EOL; }

preferences:
22.59 ms | 407 KiB | 5 Q