[PHP] Convert RGB or HEX to color "Long Int"

You must convert the RGB or HEX colors to "Long Int" for another program that uses this format. Not sure about the specifics of the "Long Int" color format.

You can manually generate "Long Int" values ​​using this color selection http://hide-inoki.com/en/soft/chunter/index.html , but the php function will be preferable.

hexdec generates the correct "Long Int" for some HEX values ​​("FFFFFF", "2F2F2F"), but not others ("123456").

+3
source share
1 answer

PHP hexdec.

hexdec('FFFFFF'): 16777215
hexdec('123456'): 1193046

.

, ? dechex ?


, , "# 123456" "5649426" "Long Int":

5649426 16 0x563412, BGR RGB.

, "BGR" "RGB", hexdec:

$rgb = '123456';
$bgr = substr($rgb,4,2) . substr($rgb,2,2) . substr($rgb,0,2);
print hexdec($bgr);

5649426.

+6

Source: https://habr.com/ru/post/1762980/


All Articles