Skip to content

Instantly share code, notes, and snippets.

@lucascardial
Last active August 26, 2020 20:22
Show Gist options
  • Save lucascardial/2692e3fb0990c65f54e82cd02bcfbc9e to your computer and use it in GitHub Desktop.
Save lucascardial/2692e3fb0990c65f54e82cd02bcfbc9e to your computer and use it in GitHub Desktop.
Random PHP
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
echo strtoupper(generateRandomString(7)).'<br/>';
$total = 7;
for($i = 1; $i <= $total; $i ++) {
echo strtoupper(generateRandomString(7)).'<br/>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment