PHP-如何随机化第一个和最后两个数字


php- how to randomize first and last two digits?

我想知道如何在 php 中随机化第一个最后两个数字?假设当前代码为:

FJA793HIYX

那么随机化后它应该是:

HJA793HIGD

我该怎么做?

尝试

$str = 'HJA793HIGD';
$filter = substr($str,1,7);
echo $newstr= randLetter().$filter.randLetter().randLetter();
function randLetter() {
  $int = rand(0,26);
  $alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $rand_letter = $alpha[$int];
  return $rand_letter;
}

试试这个!

$randomDigit = substr( "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ,mt_rand( 0 ,34 ) ,1 ) .substr( md5( time() ), 1)