3v4l.org

run code in 300+ PHP versions simultaneously
<?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( int $length = 64, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ): string { if ($length < 1) { throw new \RangeException("Length must be a positive integer"); } $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } return implode('', $pieces); } $a = random_str(32); $b = random_str(8, 'abcdefghijklmnopqrstuvwxyz'); $c = random_str(); var_dump($a, $b, $c);
Output for git.master
string(32) "MWTnnPWwLanAaiUcGaganb1uW0uadAbu" string(8) "ihlcxdja" string(64) "9WyNNEzwVtInND8NVHSsBi1eOri0H0TaN6jvS4IHp1o3jYV6BzDa5Q3eNtRuFXNK"
Output for git.master_jit
string(32) "n0AOYUA3LkstJCJ3ZGcRjxehI4Z97VRW" string(8) "ocnlwpca" string(64) "8iCGQKeJaabYef1BjusQdk2QFWtyoFfF6aJki1BSdm9tYkAOr1dUrCYSIxbLZova"
Output for rfc.property-hooks
string(32) "J6L1ITUoSXRgGjMkLZpRe6ZbDcAB4vd3" string(8) "gesskkqw" string(64) "KlAVwYU8zTMoe4c1SQEw4JwzeaRZ0D4Y6lUWXBJQhnDDKukzN8OhNpGrcpSdOzF3"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
30.31 ms | 408 KiB | 5 Q