Generating a random hex color code with PHP

后端 未结 13 2238
半阙折子戏
半阙折子戏 2020-11-28 04:21

I\'m working on a project where I need to generate an undefined number of random, hexadecimal color codes…how would I go about building such a function in PHP?

相关标签:
13条回答
  • 2020-11-28 05:13

    As of PHP 5.3, you can use openssl_random_pseudo_bytes():

    $hex_string = bin2hex(openssl_random_pseudo_bytes(3));
    
    0 讨论(0)
提交回复
热议问题