Home > php教程 > php手册 > php颜色转换函数hex-rgb

php颜色转换函数hex-rgb

WBOY
Release: 2016-06-07 11:45:13
Original
1534 people have browsed it

一个很使用的php颜色转换函数,用于将hex表示的颜色值转换为rgb格式。例如:#dfdfdf转换成(239,239,239)
<?php <br /> function hex2rgb( $colour ) {<br> if ( $colour[0] == '#' ) {<br> $colour = substr( $colour, 1 );<br> }<br> if ( strlen( $colour ) == 6 ) {<br> list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );<br> } elseif ( strlen( $colour ) == 3 ) {<br> list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );<br> } else {<br> return false;<br> }<br> $r = hexdec( $r );<br> $g = hexdec( $g );<br> $b = hexdec( $b );<br> return array( 'red' => $r, 'green' => $g, 'blue' => $b );<br> }<br> ?>http://blog.ddian.cn/?post=896

AD:真正免费,域名+虚机+企业邮箱=0元

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template