I don't know perl language, but i am trying to customize an application written in perl language. I want to know the logic or meaning of the following perl code. I know this code is for generating a random string, but i want its details i.e i want to know how can i generate this same random string in PHP? Please anyone give me the PHP code for this perl code!!
sub generate_rand_string {
#warn "generate_rand_string";
my $chars = shift
|| 'aAeEiIoOuUyYabcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';
my $num = shift || 1024;
require Digest::MD5;
my @chars = split '', $chars;
my $ran;
for ( 1 .. $num ) {
$ran .= $chars[ rand @chars ];
}
return Digest::MD5::md5_hex($ran);
}
Please anyone help me!!!!
In PHP it would like this:
function generate_rand_string($chars = null, $length = 1024) {
if($chars == null) {
$chars = 'aAeEiIoOuUyYabcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';
}
$rand = '';
for($i = 0; $i < $length; $i++) {
$rand .= $chars[ rand(0, strlen($chars) - 1) ];
}
return md5($rand);
}
Steps for emulating:
aAeEiIoOuUyYabcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789
if no string is provided1024
if no number is provided