Skip to content

Instantly share code, notes, and snippets.

@dusta
Last active April 8, 2017 08:40
Show Gist options
  • Save dusta/97d68cfcc6215973b7cc7fcf62d63314 to your computer and use it in GitHub Desktop.
Save dusta/97d68cfcc6215973b7cc7fcf62d63314 to your computer and use it in GitHub Desktop.
Function generate random string
<?php
/**
* Randomly generated string
*/
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment