加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php代码:16 进制颜色转换为 RGB 色值

发布时间:2020-12-13 20:25:27 所属栏目:PHP教程 来源:网络整理
导读:php代码:16 进制颜色转换为 RGB 色值,本文来源:芒果小站。 Copy to Clipboard 引用的内容: [www.veryhuo.com] ?php /** * 16进制颜色转换为RGB色值 * @method hex2rgb */ function hex2rgb($hexColor) { $color = str_replace('#','',$hexColor); if (st

php代码:16 进制颜色转换为 RGB 色值,本文来源:芒果小站。

Copy to Clipboard

引用的内容:[www.veryhuo.com]
<?php

/**
* 16进制颜色转换为RGB色值
* @method hex2rgb
*/
function hex2rgb($hexColor) {

$color = str_replace('#','',$hexColor);
if (strlen($color) > 3) {
$rgb = array(
'r' => hexdec(substr($color,2)),
'g' => hexdec(substr($color,2,
'b' => hexdec(substr($color,4,2))
);
} else {
$color = str_replace('#',$hexColor);
$r = substr($color,1) . substr($color,1);
$g = substr($color,1,1);
$b = substr($color,1);
$rgb = array(
'r' => hexdec($r),
'g' => hexdec($g),
'b' => hexdec($b)
);
}

return $rgb;
}

?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读