PX : code

Expression calculator by Christoph Kala
Download this code


<?php
    
print("<HTML>\n");
    print(
"<HEAD>\n");
    print(
"<TITLE>Expression calculator</TITLE>\n");
    print(
"</HEAD>\n");
    print(
"<BODY>\n");


    
// Set default expression

    
if($inputExp == ""$inputExp "0";
    
    
    
// Create form 
 
    
print("<FORM ACTION=\"$PHP_SELF\" METHOD=\"post\">\n");

    print(
"<B>Expression:</B> ");
    print(
"<INPUT ");
    print(
"TYPE=\"text\" ");
    print(
"NAME=\"inputExp\" ");
    print(
"VALUE=\"$inputExp\">\n");
    
    print(
"<INPUT ");
    print(
"TYPE=\"submit\" ");
    print(
"NAME=\"Submit_Button\" ");
    print(
"VALUE=\"Calculate\">\n");

    print(
"</FORM>\n");


    
// Caclulations 

    
$resExp "\$Result" " = " $inputExp ";";
    eval(
"$resExp");


    
// Show result 

    
print("<B>Result = "$Result "</B>\n<BR><BR>\n");

    print(
"Valid operators: +, - , * , / , % {mod}, (, )\n");    
    print(
"</BODY>\n");
    print(
"</HTML>\n");
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.