Home >Backend Development >PHP Problem >PHP randomly generates verification codes of different colors
php can use the rand() function to generate random numbers, and then use the generated random numbers in the rgb method to set the color to generate different color verification codes.
<?php //ord($ascii):得到执行字符的ASCII码值 echo ord('a'),'<br/>'; //通过ASCII码值 得到字符串 echo chr(98),'<br/>'; // php 7.0专有 幂运算 echo 2 ** 3,'<br/>'; //字符连接符. echo 'a'.'b'.'c'."<br/>"; $str=''; $str.="a"; $str.="n"; echo "$str".'<br/>'; //产生随机数 #mt_rand($min.$max); 产生随机数 echo (mt_rand(1000,9999)); echo "<br/>"; $code=""; $code.='<span style="color:rgb('.mt_rand(0,255).','.mt_rand(0,255).','.mt_rand(0,255).')">'.mt_rand(1,9).'</span>'; $code.='<span style="color:rgb('.mt_rand(0,255).','.mt_rand(0,255).','.mt_rand(0,255).')">'.mt_rand(1,9).'</span>'; $code.='<span style="color:rgb('.mt_rand(0,255).','.mt_rand(0,255).','.mt_rand(0,255).')">'.mt_rand(1,9).'</span>'; $code.='<span style="color:rgb('.mt_rand(0,255).','.mt_rand(0,255).','.mt_rand(0,255).')">'.mt_rand(1,9).'</span>'; echo "$code";
Recommended: php server
The above is the detailed content of PHP randomly generates verification codes of different colors. For more information, please follow other related articles on the PHP Chinese website!