john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

color source

<?php

function printHTML( $string )
{   print $string . "<br />\n";
}

function println( $string )
{   print $string . "\n";
}

function isValidRGBColor( $string )
{
    $result = False;
     if( isset( $string) && is_numeric( $string ) )
    {
        if( $string < 256 && $string >= 0 )
        {
            $result = True;
        }
    }
    return $result;
}

function setandnotempty( $string )
{
    $result = False;
     if( isset( $string ) && !empty( $string ) )
    {   $result = True;
    }
    return $result;
}


    printHTML( "<html><body>" );
    print "<form id='getrgbcolors' action=\"" . $_SERVER['PHP_SELF'] . "\"" . " method='post'> \n" ;
    print "red: <input type='text' id='red' name='red' > ";
    print "green: <input type='text' name='green' > ";
    print "blue: <input type='text' name='blue' > ";
    print "<br /> \n";
    printHTML( "<input type='submit' name='submit' value='submit'>" );
    printHTML( "<input type='submit' name='example' value='example'>" );
    printHTML( "</form>" );


    if( setandnotempty( $_POST[ 'example' ]  ) )
    {
        print( "<table>" );
        for( $r1=0 , $g1=0 , $b1=0   ; $r1<256; $r1+= 10 , $g1+=10 , $b1+=10 )
        {
            print( "<tr>" );
            print( "<td style='background-color:rgb($r1,0,0)'> &nbsp;$r1,0,0 </td>" );
            print( "<td style='background-color:rgb($r1,128,0)'> &nbsp;$r1,128,0 </td>" );
            print( "<td style='background-color:rgb(0,$g1,0)'> &nbsp;0,$g1,0 </td>" );
            print( "<td style='background-color:rgb(0,$g1,128)'> &nbsp;0,$g1,128 </td>" );
            print( "<td style='background-color:rgb(0,0,$b1)'> &nbsp;0,0,$b1 </td>" );
            print( "<td style='background-color:rgb(128,0,$b1)'> &nbsp;128,0,$b1 </td>" );
            print( "</tr>" );
        }
        print( "</td></table>" );
    }

    if(  isValidRGBColor( $_POST[ 'red' ] ) && isValidRGBColor( $_POST[ 'green' ] ) && isValidRGBColor( $_POST[ 'blue' ] ) )
    {
        $red =  $_POST[ 'red' ];
        $green =  $_POST[ 'green' ];
        $blue =  $_POST[ 'blue' ];
        printHTML( "red: $red , green: $green , blue: $blue " );
        printHTML( "<table><tr>" );
        printHTML( "<td style='background-color:rgb($red,$green,$blue)'> &nbsp; </td>" );
        printHTML( "</td></table>" );
    }

    println( "<script type='text/javascript' language='JavaScript'> " );
    println( "document.getElementById('red').focus();" );
    println( "</script>" );

    print "</body></html>";
?>

  • « css div override html style
  • BAT file listing get file content as variable »

Published

Feb 2, 2012

Category

php

~189 words

Tags

  • color 6
  • php 82
  • source 9