What would be a good way to convert hex color values like #ffffff
into the single RGB values 255 255 255
using PHP?
$output = sprintf('%06x', 0xffffff - hexdec(ltrim($input, '#')); however that's probably overly simplified and you'll probably want to analyse the RGB components separately, please explain exactly what it is you are wanting to do.
If you want to convert hex to rgb you can use sscanf:
<?php $hex = "#ff9900"; list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x"); echo "$hex -> $r $g $b"; ?>
Output:
#ff9900 -> 255 153 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With