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);
Output for 7.4.1
Token: DYMGmjYeIlHcSOfhk6yGYG781kixLsXU Token length: 32
Output for 7.4.0
Token: vthV0gjr5KLGo7BATuvV1C2IInNQqMeQ Token length: 32
Output for 7.3.13
Token: JWaiOl8s4WZiBCifleGngeAGXDoFPnSn Token length: 32
Output for 7.3.12
Token: 9ix9rrDTKMkxVyriG0cIW6e0WeX7qQ6l Token length: 32
Output for 7.3.11
Token: ARoIGoLPG0e3CIdWfNaixlvfkpfJXs5I Token length: 32
Output for 7.3.10
Token: qKtE80YVSu6BHiqpnGOf4nESYiUukis6 Token length: 32
Output for 7.3.9
Token: d3f2nD0wOpLQwjA2nVxmgUdUp9etxMau Token length: 32
Output for 7.3.8
Token: EhlIksThMn07FikKJJfGv1Br2OMF7lrM Token length: 32
Output for 7.3.7
Token: LsvS3Tm4m3jAthO6okxdAvtHFtTfNHzB Token length: 32
Output for 7.3.6
Token: 3DHr4XK0vcyj30tP5ceRa5Btk7z9pZ1G Token length: 32
Output for 7.3.5
Token: NkvLLK5EyMbMHWsBZlKylPH8VeNaYw8H Token length: 32
Output for 7.3.4
Token: 3OtV3GRZH15qxAKvmPMLMRP0IYnRpfyA Token length: 32
Output for 7.3.3
Token: nSGHv8BfodXJePBI8JzTgJuo2cGXPSPT Token length: 32
Output for 7.3.2
Token: 3lM27s4wIUioJZKcbAJrRWviZfUgfbMy Token length: 32
Output for 7.3.1
Token: mzvxgeUtFEtvlUeRi3seyjtXKUG3hcuX Token length: 32
Output for 7.3.0
Token: slw1onz9t0KmW1NgS5dr8XGqXjQXMsDH Token length: 32
Output for 7.2.26
Token: VmcuTFA8GfHXvqJeH7VHR2rNrbODVPiN Token length: 32
Output for 7.2.25
Token: O0x9KrMYYxvtfLoI9nStd9OWwSnI5l5o Token length: 32
Output for 7.2.24
Token: AVvmBciqYcYz8kmYzjAhe7K2abGXsFOl Token length: 32
Output for 7.2.23
Token: PvBIqpgiJOI2AF0BjcoJemiNMtO7M8eS Token length: 32
Output for 7.2.22
Token: fPQH3x6dVgmt74UXm0VjvbrfpbOIi5Ao Token length: 32
Output for 7.2.21
Token: PDlkuxyqtYo910fLTE5v9wsFxlpMP8hs Token length: 32
Output for 7.2.20
Token: VTbY4cKeLNfuzw50j6vsmnDA8XC1WD1l Token length: 32
Output for 7.2.19
Token: DVb4dIbb1P0G72AIIB8FFkpDibRuXMzd Token length: 32
Output for 7.2.18
Token: TJu43hrf3eGNALd7lukpIk5WDlgPpDLl Token length: 32
Output for 7.2.17
Token: pO9dFwzOBK004b7HJ4xghyquRbYCr5lT Token length: 32
Output for 7.2.16
Token: pU5DZPRIMhXbduDpnrVfF93i0QS3eILs Token length: 32
Output for 7.2.15
Token: JD4IW8vSiWANfikW2p8BCNmuZdgg7gP2 Token length: 32
Output for 7.2.14
Token: gwh9Da2QoZUfBinz6R80RWgdOhYORX6y Token length: 32
Output for 7.2.13
Token: daVAsBCV6UuZQeJRqKwHRKuqCBY5zL1U Token length: 32
Output for 7.2.12
Token: pz9e729lNrya5NyPxlRj1iCHToNBlchI Token length: 32
Output for 7.2.11
Token: C7NZyAFwBq2YshssBPKg6mTcjeEbbNqg Token length: 32
Output for 7.2.10
Token: oj3urph1k0g3mCDdRAVavpI864DdvBp4 Token length: 32
Output for 7.2.9
Token: nmqtAQCdJqhkmspReHpAn0deL94wyQPi Token length: 32
Output for 7.2.8
Token: L5sHDFzc8Q0OfZ1ZeabIrGto25Ahaebr Token length: 32
Output for 7.2.7
Token: h34j3a9u8NkOevMtHdPeaej2sLdnmjVg Token length: 32
Output for 7.2.6
Token: 0RhzBcTysZR3WWKPcMU0uXmhDcmZPhkN Token length: 32
Output for 7.2.5
Token: 60c2oE9vmaZXbTsHKkP6UCJTUwUheKLI Token length: 32
Output for 7.2.4
Token: gT8oFgwVkV3Wcvl8TAuAym8RUbAxnLhu Token length: 32
Output for 7.2.3
Token: Vg2oa88CUjtlFZKM8dIk137LakvBmBmp Token length: 32
Output for 7.2.2
Token: LEq0vp0gWq1TWU6jFjOvCE9Cd0Ur39qC Token length: 32
Output for 7.2.1
Token: a63VN4UnXfBTO7y6Be2RRom4xXFy1KNH Token length: 32
Output for 7.2.0
Token: SAoMo8sQ79SBXEvgERSZaHAU3EoWpqRI Token length: 32
Output for 7.1.33
Token: I5smuzT7NTMD6VJrou8Rx1jsXz4qZVdP Token length: 32
Output for 7.1.32
Token: JbXLYpPQ18y8fjQKYTeAgHdLHqz1jXWU Token length: 32
Output for 7.1.31
Token: P2vDfZzgSOKY5PdFNIGDrbDNQLAVOiWI Token length: 32
Output for 7.1.30
Token: Dj9ABZDGPMpwY7I4SOUawbaawwF0vGQw Token length: 32
Output for 7.1.29
Token: wZBcnsmFCpkqgKTlFLOhXNFVTPrfKSRw Token length: 32
Output for 7.1.28
Token: xFOioLCx921pP5rJgNUOqmyZ2qm2K8MR Token length: 32
Output for 7.1.27
Token: rqX0kwWU4dHTHn6h61GKjmft7xOo9fR9 Token length: 32
Output for 7.1.26
Token: a5xFBjzfa76jDooHvbk36mzYPFP8p6Cl Token length: 32

preferences:
53.62 ms | 475 KiB | 5 Q