3v4l.org

run code in 200+ 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 7.4.0beta1
string(32) "a2JhsalvozXZYSorIkKykbQb2vDuxOKv" string(8) "hdhqjvxp" string(64) "bFbk1cmuUS8Mm1oPwJeyzhC2pZWiyP1GiJfZc5KtlFJn3noZnEWbwVSKR0AlMmXl"
Output for 7.4.0alpha3
string(32) "lQmRGVSda18XD3x5YEXlHDUcWBjhWZVx" string(8) "gdtdgmkq" string(64) "mLA4qAMl2X7og2McJvH5jYHZe8fN0m02Yktj2yWKoUPQi1ko0girexFXXVZDmIap"
Output for 7.4.0alpha2
string(32) "E5B80I9cqeg4aqgfMj6KRBeUuod80Oa9" string(8) "bpmoxejs" string(64) "hGAwmoPuXaWuS8ZtdjU5KqzbZF9bLLCK3SSGd6sznCfdGb9ofwTdNcvVruUKMdJQ"
Output for 7.4.0alpha1
string(32) "eqeQOH2b7165yfhaQl6IvnkhPB8ageMM" string(8) "yoomvamy" string(64) "Nhepa5MJouEOUN9UldCABHawmC1XXuDjwdOketrc15BXZVLEi9823SklHPmbAZfy"
Output for 7.3.7
string(32) "cHihNNl9L9gacV9VurdO7D82ImQ3ZB4B" string(8) "plmuiyvq" string(64) "VjDOTN1sqdiaMe0JnY58Qy3QJwdA82MhI0Dy9hE1nNlfmIYjEnmnDXP4OnS8pLgv"
Output for 7.3.6
string(32) "f50tDXmLGjeE8uWsbGM5oWnSnvYnD5aa" string(8) "hghluqoc" string(64) "jCBlDTrp3RT2d7le6ynL7nTc9JW9LqAAmiiL41XkQvgPC3xBBuGavTvEPNs17X9n"
Output for 7.3.5
string(32) "HbNFBS6Y7b8ANwEcy4BosJBCKYC9lJ6q" string(8) "sbfgtwep" string(64) "rYSBFFL1KlXPjvIWOOwLU7jIeG6EtK4byCLgvBTeClSZUDXhOkINUnngDTu8CfRQ"
Output for 7.3.4
string(32) "y6JZF1qZs63VcC7TZMigb5oHWeqVHpFV" string(8) "neqfxbhy" string(64) "cI8NNATJozn5oT0jyk0dRIEiRz0pmV39vGEObmdEPXzrW31J41uxXDHPiN59UtkX"
Output for 7.3.3
string(32) "X4oe1i4FEzjMPPhFVwt131y52ACzV1DM" string(8) "ontaiofg" string(64) "ojE3DbLhdG0mzRmEQ5bgEG68c9UjmDf94SoRWOfNXixFM2fABkpELyrZ36PEMya2"
Output for 7.3.2
string(32) "szvVnhiydEfZ4BhuN78M0PszWXYPXY1b" string(8) "kgpjnqmw" string(64) "tO1yZRTrw28JAq8xZfoB2BVek9fLjUk7BjpT0hNGGqC2GbEZECQupQO3Ug3yCLNc"
Output for 7.3.1
string(32) "tTUtT3mDt5BkongWABhPcCXfodYpushW" string(8) "ergxzjjh" string(64) "RY3sYdKiuw4m4OS2k02amNX6JtJmzfpFgPrkCfRF4BkzcHuyG5sGTgDZekRizWcu"
Output for 7.3.0
string(32) "pHMR3VWXmPNli55wQ6jLQnvfbES5jShu" string(8) "lvktykhq" string(64) "xPfsgx1Z9EOubuFPwdwFJXwmuHjsTdwuDopAUVKuoutzWT8naKHFINVKTseq58Qj"
Output for 7.2.20
string(32) "lWVYCtIJXoQHgcgpTGqfDVS8z9RZS7hN" string(8) "trrpkbjl" string(64) "6LmPPHJXBoHmSFOjixyOxqshCKZ2Uaw0Y9uVYceWQCuhezgQWxinaOkuKBtIZGe7"
Output for 7.2.19
string(32) "4fpQLENKH0rqt8v6k9EgedfhmBVnULJZ" string(8) "bdaovkxt" string(64) "mLMTIPEY6yhkdlMneGxXKYeYjGQKQS3hI5pVCwf6SUjqXFrObDRhpS7QllkPqLNM"
Output for 7.2.18
string(32) "SdWsY8JhD8nAowmXwyW79vqawHXz0Egg" string(8) "rrydrsys" string(64) "fDRzHVdEwJLgapPHLvGu79C0ivzdEatKEX5o6TzI0evak0z6N3KajKSTlqrJ3FvG"
Output for 7.2.17
string(32) "zuzjgS922vkALag0WWHLu0OdlAKqMvfH" string(8) "upyprxtl" string(64) "CWiR4IVlNjXBnxB7IbbtxT2NggDtSAqvHAi7NbAIDRHXtLAqiGGUtJvwhdVAoA1Z"
Output for 7.2.16
string(32) "hkKb3CA9otjdKaIJ1f518fMVFwtdof0C" string(8) "gnfeldsi" string(64) "OssgBbYe0Gcrsuq9C0nHFW2flzCb4gwBR8tvj12sEYkiNBU1unQHQTYIr5ftKfZz"
Output for 7.2.15
string(32) "S05QVb6L4AvQ9Ud1P9x2HMIViJ39w3Iz" string(8) "rqpgkszz" string(64) "Pr4gIPO0uukLTHVy3PVHYdTkbEXVYFChMU2M2MbPz0aTDS3f5WV7YI1kEVpnzKMf"
Output for 7.2.14
string(32) "GcwgEfyqtRZzuBVZsSBXS2DpRhbiqnDE" string(8) "tfuoxdbj" string(64) "uCHcdWoKtXJxUxnMXOQTisQLq2XJWVrKAbbRVgNubvaMPGTdyLphJagSLOVCE9em"
Output for 7.2.13
string(32) "Ar5xLQfO9UUuTj13s2V991IjaoTQDktO" string(8) "ccdjclsh" string(64) "NENhfuALrX4efDSEw4ARMIyyJM2c9JcApDXHSpS48zBLFd8bXrgavuRaelSKMjiI"
Output for 7.2.12
string(32) "wqmnDTRZgIuYKxSPDiWyFCCjBr6vRfY6" string(8) "mzunberi" string(64) "LUAgYOZyhJfbIy0aL6SfLzc3uwJZa1zvsXHcRBQPY5xdJ2yXOlUZlA07qaZhMyWF"
Output for 7.2.11
string(32) "W3d9Aqoxdb5QYWUwUBpEoJKZ5IApHZV4" string(8) "xjewwyrs" string(64) "Aq3Ecq69fcA8MT11UdnI8afx14CkIg0y5tgxdthzHoU9goy71kg4MjiZ3qmdcsRe"
Output for 7.2.10
string(32) "tmNEBplMHZ1dvcimPTPuvfrlx2Csa9gx" string(8) "cekxqvlt" string(64) "r8Qv38J0dG8fONi0fph1TtcQzjXstuoXdnBC5n09hqw2lEzSS56hevpgoPSli5mx"
Output for 7.2.9
string(32) "Mn7wP59OcZzFTdTc4glBCHW7iwKFWumb" string(8) "jmeqnubi" string(64) "QbEzt6RzLORiiTsMHzp0MLEFFm99oeia3XNfl261zuHhed7fJMO5cMnpI2PVVYjr"
Output for 7.2.8
string(32) "E4g2g3j8SAyvrYadlVUvBtfvZ4yYBwvt" string(8) "arqxchlh" string(64) "JTKz83vgqMjTynIxvd1IwmgF9ZONDbZZheVSroGFsHxKXdqsK6RaKezGZcNCRkq2"
Output for 7.2.7
string(32) "PrxKuY6XdaDQ7w0eoSRCy950erqMVbfy" string(8) "pojcsaul" string(64) "AbCPLXnOeRiEB0O7deJLajNEDUIjmnLzRT3pzk1ni1LyvUxcHBid673BKTSQsoWK"
Output for 7.2.6
string(32) "5yz4GY4MQS149xxPssnyG97SKKyatkWi" string(8) "oqlujrap" string(64) "9DJ5Omf1i9xHl2qzX6AAmy4C5RYj62tJX8DG7fmcfTjmCHgzHnUOUaqAdgwS5ZFK"
Output for 7.2.5
string(32) "JyMqrJugl1ZqUpWRRBgfiIJtphegjdNn" string(8) "lafptvwz" string(64) "VcnTLlSDejGLuB9CJT6nKkm4wmnLYs8kyQJzMINIkG49j4qIJk7Pr6e2Dnz3rGFW"
Output for 7.2.4
string(32) "FL7PSKYZGul8P8LH5H4QQ7etf5qQDxxt" string(8) "swrkfsun" string(64) "9KYxxQ3vtRyJKn0mOWcYDz6QZ2eMQMbxGcCSsbGIKSTSoXAmbPVwNmaJGCgqoiQ0"
Output for 7.2.3
string(32) "OJlTGRGpYzVgw1luB7znR0TostPKnW5X" string(8) "atgtunqr" string(64) "Cm5UJqXG0WpVZFOef011D7mcSYSFT4t26Lcp4Me25BQtapfr8FE8YMYDxYy09xiR"
Output for 7.2.2
string(32) "QvkY4wmnCu8R0v6Kvnsv2lXoKOLVA9vr" string(8) "vccllznb" string(64) "Tl6xEUOr4nhSiTuTpgJBLMijAt4GiMqF3lASHgZrNW8cSq6eEYnCcrgHJn7AHiQ9"
Output for 7.2.1
string(32) "n0K3fZ1ICU3W9ueKqRSUJsgiyG1GWf3H" string(8) "tlmdjtig" string(64) "oo7vDZD59Xr8nk0OAXpp8MiwvkcDwSrNVy2WyQpxMXqDevWwuF9QsxcVCXsyIM6x"
Output for 7.2.0
string(32) "znC0pTUPVcCTyRmgpCEC8qI9lFXt4Htm" string(8) "dvbdkajq" string(64) "yILsb9Iaxw6xutNtAUWWh0wagbWkGKRNt6I8l3jItHW6DdyOWzJVU5jMoDA6XFDg"
Output for 7.1.30
string(32) "uymotVa9dvmEKz7jEB1dfJaaWfU2QyVD" string(8) "ngybwfgs" string(64) "bAj6cNGln7TPuOdebSkseHCqPZysbnSLpKSVef6LVkAKzNDyb5KaHrgk5OsBS5nY"
Output for 7.1.29
string(32) "ILTmjMlq7N1Wh3qpmW7NtOq2RMBc6UQ4" string(8) "qdhchlai" string(64) "kAPT509ET3zzG1Jv5RXYrFsdiGRXLHxJcx5VHwaOCmdtNQCa2hffeXoNmPbDMUX2"
Output for 7.1.28
string(32) "rLzySSrBPc6cLqdAGtLh9v13EPiP1G7n" string(8) "bslipsbm" string(64) "CbwTqfBkziTa174tysUm12vCAtibJ6MsBvAHswhtLsck3Nvwjta2SwrARQizwJbf"
Output for 7.1.27
string(32) "K6KYEoaEdAnW3rSKGLb316yImP1ZWYMk" string(8) "escrvonr" string(64) "tkeGjA9fm35RtZvS8EyxfTLoUILm4wB6zqYbWiSGL82uwCuvP131TBkZw5x2xjZY"
Output for 7.1.26
string(32) "kNLiN0K51OmiJiBaakwNbGGs8DCRBJvf" string(8) "srvchjvm" string(64) "UuXXxN5IDX3uXV4NNRbpE28aC78F4kRx4NNVmRxWPy5HpJo1eW8oRSYOV2fIF5VS"
Output for 7.1.25
string(32) "ijTB8otyOAkgfRBSYvGs8cwg3aauhsd4" string(8) "nhwcylmw" string(64) "kRdP6ZwwUsJ0XFTXKCNKtgMTVg2HX6jG7hOa1FbtR0v0zrKV0CQmQaNhBgCKU7JH"