Location: PHPKode > scripts > Hexadecimal 2 RGB Converter > ekdevdes-hexadecimal2rgb-6c63693/index.php
<?php

	function hex2rgb( $colour ) {
	        if ( $colour[0] == '#' ) {
	                $colour = substr( $colour, 1 );
	        }
	        if ( strlen( $colour ) == 6 ) {
	                list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
	        } elseif ( strlen( $colour ) == 3 ) {
	                list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
	        } else {
	                return false;
	        }
	        $r = hexdec( $r );
	        $g = hexdec( $g );
	        $b = hexdec( $b );
	        return array( 'red' => $r, 'green' => $g, 'blue' => $b );
	}

?>

<!DOCTYPE html>  

<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --> 
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
  <meta charset="utf-8">

  <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame 
       Remove this if you use the .htaccess -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title>Simple Hexadecimal to RGB Converter</title>

  <!--  Mobile viewport optimized: j.mp/bplateviewport -->
  <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->

   <style type="text/css">body{font-family:Arial;}input{-moz-border-radius: 8px; 
   -webkit-border-radius:8px; 
   border-radius:8px; border:1px solid #e3e3e3;font-size:20px;padding:15px;}button{border:none;font-size:20px;padding:15px;background:#e6e6e6;-moz-border-radius: 8px; 
   -webkit-border-radius:8px; 
   border-radius:8px;color:#676767;border:1px solid #676767;cursor:pointer;}p{font-size:20px;}input:focus{outline:none;}</style>

  <!-- Uncomment if you are specifically targeting less enabled mobile browsers
  <link rel="stylesheet" media="handheld" href="css/handheld.css?v=2">  -->
 
  <!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects -->
  <script src="js/libs/modernizr-1.6.min.js"></script>

</head>

<body>

  <div id="container">
    <h1>Hexadecimal 2 RGB Color Converter</h1>
	<br /><br />
	<div class="content">
		<form action="" method="post">
			<input type="text" name="color" />
			<button type="submit" name="submit">Go!</button>
		</form>
		<br /><br />
		<div class="rgb">
			<p>
				<?php 
				
					if(isset($_POST['color']) && !empty($_POST['color'])){
						$color = $_POST['color'];
						$rgb = hex2rgb($color);
						echo 'rgb('.$rgb['red'].','.$rgb['green'].','.$rgb['blue'].')';	
					}elseif(empty($_POST['color'])){
						echo 'Please enter a hexadecimal color first!';
					}
				
				?>
			</p>
		</div>
	</div>
  </div> <!--! end of #container -->


  <!-- Javascript at the bottom for fast page loading -->

  <!-- Grab Google CDN's jQuery. fall back to local if necessary -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
  <script>!window.jQuery && document.write(unescape('?script src="js/libs/jquery-1.4.2.js"??/script?'))</script>
  
  
  <!-- scripts concatenated and minified via ant build script-->
  <script src="js/plugins.js"></script>
  <script src="js/script.js"></script>
  <!-- end concatenated and minified scripts-->
  
  
  <!--[if lt IE 7 ]>
    <script src="js/libs/dd_belatedpng.js"></script>
    <script> DD_belatedPNG.fix('img, .png_bg'); //fix any <img> or .png_bg background-images </script>
  <![endif]-->

  <!-- yui profiler and profileviewer - remove for production -->
  <script src="js/profiling/yahoo-profiling.min.js"></script>
  <script src="js/profiling/config.js"></script>
  <!-- end profiling code -->
  
</body>
</html>
Return current item: Hexadecimal 2 RGB Converter