Forum Moderators: coopster
I found this code on this forum and it works but i don't know what the lines in bold mean.
$data = "AbcDE123GHIJK4LMN567QRSTU89VWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
$Random .= substr($data, (rand()%(strlen($data))), 1);
Can someone please explain them to me.
Thanks in advance,
Scoobie.
Essentially, here is what $data looks like:
$data = "AbcDE123GHIJK4LMN567QRSTU89VWXYZaBCdefghijklmn123opq45rs67tuv89wxyz0FGH45OP89";
You can lookup the defintion of substr on php.net. It basically takes only a part of the string (hence, sub-string).
In this specific piece of code, I'm assuming it's inside a loop since it's appending one character at a time to $Random.
rand() geneartes a random number, and % is the modulous operator that returns the remainder of the division of rand() by strlen($data)
The purpose of (rand()%(strlen($data))) is to generate a random number which will be used as an offset to start cutting from in substr.