日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

php 随机颜色,php生成随机颜色的代码实例

發(fā)布時(shí)間:2024/7/23 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 随机颜色,php生成随机颜色的代码实例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

PHP生成隨機(jī)顏色的代碼實(shí)例:

方法一:

function color_txt($str){

if ( is_array($str) )

{

$str = $str[1];

}

$len??????? = mb_strlen($str);

$colorTxt?? = '';

for($i=0; $i

$colorTxt .=? ''.mb_substr($str,$i,1,'utf-8').'';

}

return $colorTxt;

}

function rand_color(){

return '#'.sprintf("%02X",mt_rand(0,255)).sprintf("%02X",mt_rand(0,255)).sprintf("%02X",mt_rand(0,255));

}

方法二:

function randrgb()

{

$str='0123456789ABCDEF';

$estr='#';

$len=strlen($str);

for($i=1;$i<=6;$i++)

{

$num=rand(0,$len-1);

$estr=$estr.$str[$num];

}

return $estr;

}

方法三:

function randColor(){

$colors = array();

for($i = 0;$i<6;$i++){

$colors[] = dechex(rand(0,15));

}

return implode('',$colors);

}

方法四:

/**

* 隨機(jī)顏色生成

* @author LJ

* @date 2017-02-09

*/

function randomColor() {

// 顏色 例:#866573

$str = '#';

for($i = 0 ; $i < 6 ; $i++) {

$randNum = rand(0 , 15);

switch ($randNum) {

case 10:

$randNum = 'A';

break;

case 11:

$randNum = 'B';

break;

case 12:

$randNum = 'C';

break;

case 13:

$randNum = 'D';

break;

case 14:

$randNum = 'E';

break;

case 15:

$randNum = 'F';

break;

}

$str .= $randNum;

}

return $str;

}

$color = randomColor();

方法五:

隨機(jī)挑選數(shù)組里的顏色

function randColor(){

$colors=array('5CB85C','428BCA','FF6600','D9534F','B37333','00ABA9');

$show_color = array_rand($colors, 1);

return $colors[$show_color];

}

?>

總結(jié)

以上是生活随笔為你收集整理的php 随机颜色,php生成随机颜色的代码实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。