drob50257447 2017-09-09 14:22
浏览 142
已采纳

dechex没有显示前两个零(rgb到十六进制php)[重复]

This question already has an answer here:

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?

</div>
  • 写回答

1条回答 默认 最新

  • douzhong8856 2017-09-09 14:26
    关注

    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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测