3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://www.strangebuzz.com/en/snippets/convert-a-string-into-an-array-of-characters $tokenSize = 32; try { $random = random_bytes($tokenSize); } catch (\Exception $e) { throw new \RuntimeException('Unable to get random_bytes.'); } $base = base64_encode($random); $clean = str_replace(str_split('+/-_'), '', $base); $cut = substr($clean, 0, $tokenSize); echo 'Token: '.$cut."\n"; echo 'Token length: '.strlen($cut);

preferences:
31.85 ms | 402 KiB | 5 Q