Login   Register  
PHP Classes

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Miles Kaufmann  >  Eval Math  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Generates a table from user input
Class: Eval Math
Safely evaluate mathematical expressions
Author: By
Last change: Making accessible without user login
Date: 9 years ago
Size: 933 bytes


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

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