Table of Contents
php 函数将16进制颜色代码转换为 RGB 色值
您可能感兴趣的文章
Home php教程 php手册 php 函数将16进制颜色代码转换为 RGB 色值

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

Jun 13, 2016 am 09:04 AM
php rgb

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实现限制域名从而保护源代码不被拷贝
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles