Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Created June 28, 2014 05:30
Show Gist options
  • Save joseluisq/1385fb9c1992a06cdbb3 to your computer and use it in GitHub Desktop.
Save joseluisq/1385fb9c1992a06cdbb3 to your computer and use it in GitHub Desktop.
Generate a random string with PHP
<?php
function random_string($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment