function rcolor() { $rand = rand(0,255);//随机获取0--255的数字 return sprintf("%02X","$rand");//输出十六进制的两个大写字母 } function rand_color(){ return '#'.rcolor().rcolor().rcolor();//六个字母 } echo rand_color();简单写法: echo '#'.sprintf('%02X',rand(0,255)).sprintf('%02X',rand(0,255)).sprintf('%02X',rand(0,255)); |
GMT+8, 2024-5-20 19:51 , Processed in 0.248588 second(s), 12 queries , Xcache On.
Powered by Discuz! X3.2
© 2001-2013 Comsenz Inc.