PHP Classes
Icontem

File: example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Miles Kaufmann  >  Eval Math  >  example.php  
File: example.php
Role: Example script
Content type: text/plain
Description: Generates a table from user input
Class: Eval Math
Safely evaluate mathematical expressions
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
    <title>Example use of EvalMath</title>
</head>

<body>
    <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
        y(x) = <input type="text" name="function" value="<?=(isset($_POST['function']) ? htmlspecialchars($_POST['function']) : '')?>">
        <input type="submit">
    </form>
    <?
if (isset($_POST['function']) and $_POST['function']) {
    include(
'evalmath.class.php');
    
$m = new EvalMath;
    
$m->suppress_errors true;
    if (
$m->evaluate('y(x) = ' $_POST['function'])) {
        print 
"\t<table border=\"1\">\n";
        print 
"\t\t<tr><th>x</th><th>y(x)</th>\n";
        for (
$x = -2$x <= 2$x+=.2) {
            
$x round($x2);
            print 
"\t\t<tr><td>$x</td><td>" $m->e("y($x)") . "</td></tr>\n";
        }
        print 
"\t</table>\n";
    } else {
        print 
"\t<p>Could not evaluate function: " $m->last_error "</p>\n";
    }
}
?>
</body>
</html>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products