<?php
error_reporting
(E_ALL);   
ini_set('display_errors'TRUE); 

if(isset(
$_GET['action']) && 'showsource' === $_GET['action'])
{
  
highlight_file(__FILE__);
  exit;
}
if(isset(
$_GET['action']) && 'download' === $_GET['action'])
{
    
header("Content-type: application/x-applikation");
    
readfile(__FILE__);
    exit; 
}

function 
farbtabelle()
{
  
$pool = array('00','33','66','99','CC','FF');
  
$content '';
  
$content .= '<table>';
  foreach(
$pool as $g_index => $gruen)
  {
    foreach(
$pool as $r_index => $rot)
    {
      
$content .=  '<tr>';
      foreach(
$pool as $b_index => $blau)
      {
         
$bgcolor '#'.$rot.$gruen.$blau;
         
$textcolor = (($r_index*1.4+$g_index*2.5+$b_index) > 10)?'#000' :'#fff';
         
$style ' style=" background-color:'.$bgcolor.'; color:'.$textcolor.'" ';
         
$javascript ' onclick="farbClick(\''.$bgcolor.'\')" ';
         
$content .=  '<td '.$style.$javascript.'>';
         
$content .=  $bgcolor ;
         
$content .=  '</td> ';
      }
      
$content .=  '</tr>';
    }
  }
  
$content .=  '</table>';
  return 
$content ;
}
?>


<script type="text/javascript">
function farbClick(farbe)
{
   document.getElementById("testfeld").style.backgroundColor = farbe;

</script>

 Quellcode:  
<a href="?action=showsource"> Zeige </a>
 || 
 <a href="?action=download"> Download  </a>
<br />
<table width="100%">
  <tr>
    <td><?php echo farbtabelle(); ?></td>
    <td id="testfeld" width="50%">Testfeld</td>
  </tr>
</table>