Zend - The PHP Company




Graphics

Add Code


Change colour format  

Type: code fragment
Added by: robf
Entered: 14/03/2000
Last modified: 08/12/1999
Rating: **** (3 votes)
Views: 6923
Takes a hex colour in standard HTML format and returns a three element array in which each element is the decimal R, G, or B value which can then be used, for instance, in GD funcitons


<?php
function col_hexdec($colour) {

    
/* Takes a hex colour in standard HTML format and returns a three element
     * array in which each element is the decimal R, G, or B value which can
     * then be used, for instance, in GD funcitons
     */

    /* Strip of the leading hash, if we've been passed one */

    
$colour str_replace("#"""$colour);

    
/* Split the hex string into 2 digit chunks and convert each part into
     * decimal
     */

    
for ($i 0$i 6$i += 2) {
        
$array[] = hexdec(substr($colour$i2));
    }

    return 
$array;

}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories