H8OV7-HNTB5-JLLOH-W8FG2
.$tokens
string contains the characters that are valid in the key, so the loop can pick from it. The $segment_chars
and $num_segments
variables are the number of characters in a segment and the number of segments in the key, respectively. $key_string
is an empty string that the loop will add the characters into.$tokens
at random each time it goes around. (PHP strings are also arrays, with the each character having its own numerical offset.) The characters are tacked onto the $segment
string.$key_string
, and a dash character is applied if the loop isn’t on the final segment yet. End result: something like H8OV7-HNTB5-JLLOH-W8FG2
.