Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何通过 PHP 从颜色字符串中获取单独的通道,例如:“#1122f0”来获得这个:
$color = substr("#1122f0", 1); // get "1122f0" // wanted: $red = 0x11; $green = 0x22; $blue = 0xf0;
list($red, $green, $blue) = array_map('dechex', sscanf('#1122f0', '#%02x%02x%02x'));
您还可以将组件解析为字符串:
list($red, $green, $blue) = sscanf('#1122f0', '#%02s%02s%02s');
但是第一个解决方案也会(某种程度上)验证您的颜色字符串:)