php 函数将16进制颜色代码转换为 RGB 色值_PHP教程

WBOY
Release: 2016-07-13 09:53:31
Original
944 people have browsed it

php 函数将16进制颜色代码转换为 RGB 色值

利用php函数将16禁止的颜色代码转换为RGB色值。

/** 
* function 16进制颜色转换为RGB色值
* author www.phpernote.com
*/ 
function hex2rgb($hexColor){
	$color=str_replace('#','',$hexColor);
	if (strlen($color)> 3){
		$rgb=array(
			'r'=>hexdec(substr($color,0,2)),
			'g'=>hexdec(substr($color,2,2)),
			'b'=>hexdec(substr($color,4,2))
		);
	}else{
		$color=str_replace('#','',$hexColor);
		$r=substr($color,0,1). substr($color,0,1);
		$g=substr($color,1,1). substr($color,1,1);
		$b=substr($color,2,1). substr($color,2,1);
		$rgb=array( 
			'r'=>hexdec($r),
			'g'=>hexdec($g),
			'b'=>hexdec($b)
		);
	}
	return $rgb;
}
Copy after login

例如:

print_r(hex2rgb('#F03'));
//输出:Array ( [r] => 255 [g] => 0 [b] => 51 )
Copy after login

您可能感兴趣的文章

  • php如何将html中的br换行符转换为文本输入中的换行符
  • php 将字符串中的连续多个空格转换为一个空格
  • php将字符串中全角字符转换为半角字符
  • js如何将返回的字符串转换为json格式的数据
  • php利用session_set_save_handler()函数将session保存到MySQL数据库中
  • php将IP地址转换为真实地址的方法
  • php用ZipArchive函数实现文件的压缩与解压缩
  • PHP实现限制域名从而保护源代码不被拷贝

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1000763.htmlTechArticlephp 函数将16进制颜色代码转换为 RGB 色值 利用php函数将16禁止的颜色代码转换为RGB色值。 /** * function 16进制颜色转换为RGB色值* author www.php...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!