3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * For PHP 7, random_int is a PHP core function * For PHP 5.x, depends on https://github.com/paragonie/random_compat * * @param int $length How many characters do we want? * @param string $keyspace A string of all possible characters * to select from * @return string */ function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } $str = random_str(8) var_dump(random_str(32)); var_dump($str); var_dump($str);
based on ZeY7R
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.7
Parse error: syntax error, unexpected 'var_dump' (T_STRING) in /in/GuCqt on line 25
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: syntax error, unexpected T_STRING in /in/GuCqt:25 Stack trace: #0 {main}
Process exited with code 255.