转换为3位十六进制颜色代码 [英] convert to 3-digit hex color code

查看:2238
本文介绍了转换为3位十六进制颜色代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在CSS中使用3位十六进制颜色值: #fff #999 #069 等。我可以看到重复的字母/数字如何合并创建一个3位的十六进制颜色代码,但我不完全理解模式能够在PHP中编写转换器。有这样的文档吗?

I've been using 3-digit hex color values in CSS for a long time: #fff, #999, #069, etc. I can see how the repeating letters/numbers are merged to create a 3-digit hex color code, but I don't fully understand the pattern to be able to write a converter in PHP. Is there documentation for this?

编辑:哦,也许我的问题不清楚。我需要知道一些6位十六进制颜色值如何转换为3位数。 xxxxxx ffffff )和 xxyyzz (<$ c $

Oh, perhaps my question wasn't clear. I need to know how some of the 6-digit hex color values are converted to 3-digits. xxxxxx (ffffff) and xxyyzz (006699) – these are the only two patterns, correct?

推荐答案

要转换3 -character十六进制代码转换为6个字符的一个,需要重复每个字符:

To convert a 3-character hex code into a 6 character one, you need to repeat each character:

$hex = '#fff';
$hex6 = '#' . $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];

如果要将其转换为十进制,可以使用 hexdec 函数

If you want to convert it to decimal you can use the hexdec function

这篇关于转换为3位十六进制颜色代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆