Reputation: 10649
Is there any way to use a regex expression to create a string, instead of just finding if a match exists?
I have a function to create a random string of characters:
public function getRandomString($length=8) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters)-1)];
}
return $string;
} // End
I was wondering if there was any way to use a regex expression like /[a-zA-Z0-9]
instead of typing out all the characters...?
Upvotes: 1
Views: 42