john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

color

<?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;
}


    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'>" );
    printHTML( "</form>" );

    //should only return a boolean
    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>" );
    }else{
            printHTML( "Invalid Colors, try 255,0,0 or 0,255,0 or 0,0,255" );
        }

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

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

  • « memcache cas lock race condition
  • google app engine fixtures testbed unit testing »

Published

May 30, 2013

Category

php

~132 words

Tags

  • color 6
  • php 82