Jump to content

split key prob


james182

Recommended Posts

ok i have a random key generator which works fine but i need to split it into groups of 4 and seperated by "-".

eg: 0000-0000-0000-0000-0000 <- this is may goal.

 

Below is my code so far.

function str_makerand($country, $state, $minlength, $maxlength, $useupper, $usespecial, $usenumbers){

$charset = "abcdefghijklmnopqrstuvwxyz";
if ($useupper) $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($usenumbers) $charset .= "0123456789";
if ($usespecial) $charset .= "~@#$%^*()_+-={}|]["; // Note: using all special characters this reads: "~!@#$%^&*()_+`-={}|\\]?[\":;'><,./";

if ($minlength > $maxlength){
	$length = mt_rand ($maxlength, $minlength);
}else{
	$length = mt_rand ($minlength, $maxlength);
	for ($i=0; $i<$length; $i++){
		$key .= $charset[(mt_rand(0,(strlen($charset)-1)))];
	}
}
$seq = $country ."". $state ."". $key;

// split string to XXXX-XXXX-XXXX-XXXX-XXXX

return $seq;
}

Link to comment
https://forums.phpfreaks.com/topic/154165-split-key-prob/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.