0

I use this php script to get the rgb color from a jpg file:

source: https://stackoverflow.com/a/36321726/8144877

the problem is when the rgb color look like this: rgb(0, 23, 110) then the script returns this hex: 176e and not 00176e

I see that the script not showing the first two zeros, is there a way to showing all the zeros when using dechex to convert rgb to hex?

abyse
  • 3
  • 2

1 Answers1

3

Yes, there's a way, str_pad function is there to help you:

str_pad("176e", 6, "0", STR_PAD_LEFT); // "00176e"

Arguments:

  1. input string
  2. expected length
  3. padding character
  4. padding mode - in your case STR_PAD_LEFT is needed to pad on the left side
juzraai
  • 5,693
  • 8
  • 33
  • 47