如何从色彩字符串中获取单独的通道,例如:“#1122f0”,通过PHP获取此信息:
$color = substr("#1122f0", 1); // get "1122f0"
// wanted:
$red = 0x11;
$green = 0x22;
$blue = 0xf0;
答案 0 :(得分:1)
list($red, $green, $blue) = array_map('dechex',
sscanf('#1122f0', '#%02x%02x%02x'));
您还可以将组件解析为字符串:
list($red, $green, $blue) = sscanf('#1122f0', '#%02s%02s%02s');
但是第一个解决方案也会(有点)验证你的颜色字符串:)