Home > Backend Development > PHP Problem > PHP randomly generates verification codes of different colors

PHP randomly generates verification codes of different colors

Release: 2023-02-27 19:36:01
Original
3585 people have browsed it

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(&#39;a&#39;),&#39;<br/>&#39;;
//通过ASCII码值 得到字符串
echo chr(98),&#39;<br/>&#39;;
// php 7.0专有 幂运算
echo 2 ** 3,&#39;<br/>&#39;;
//字符连接符.
echo &#39;a&#39;.&#39;b&#39;.&#39;c&#39;."<br/>";
$str=&#39;&#39;;
$str.="a";
$str.="n";
echo "$str".&#39;<br/>&#39;;
//产生随机数
#mt_rand($min.$max); 产生随机数
echo (mt_rand(1000,9999));
echo "<br/>";
$code="";
$code.=&#39;<span style="color:rgb(&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;)">&#39;.mt_rand(1,9).&#39;</span>&#39;;
$code.=&#39;<span style="color:rgb(&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;)">&#39;.mt_rand(1,9).&#39;</span>&#39;;
$code.=&#39;<span style="color:rgb(&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;)">&#39;.mt_rand(1,9).&#39;</span>&#39;;
$code.=&#39;<span style="color:rgb(&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;,&#39;.mt_rand(0,255).&#39;)">&#39;.mt_rand(1,9).&#39;</span>&#39;;
echo "$code";
Copy after login

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!

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template