PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Arturo Gonzalez-Mata Santana  >  Simple RPN Interpreter  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example of use of rpn.class.php with forms
Class: Simple RPN Interpreter
Evaluate reverse polish notation expressions
Author: By
Last change: //added some coments
Date: 14 years ago
Size: 3,925 bytes


Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<title>RPN interpreter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
.style3 {
    color: #CCCCCC;
    font-size: large;
    font-weight: bold;
    font-family: "Courier New", Courier, mono;
.style4 {color: #990000}
.style5 {font-family: "Courier New", Courier, mono}
.style7 {font-family: "Courier New", Courier, mono; font-weight: bold; }
.style8 {color: #FFFFFF}
.style9 {font-size: small}
.style10 { font-size: medium;
    font-weight: bold;
<span class="style5 style1"><a href="index.html"><tt></tt></a> <tt><a href="rpn.html">RPN Interpreter (NEW)</a></tt> </span>
<h1 align="center">EXAMPLE OF<br />
   <span class="style4">RPN INTERPRETER IN PHP</span> </h1>
 <h3>(C) Arturo Gonzalez-Mata Santana </h3>
 <p>This example read and execute a RPN commands in the form. </p>

$s=&new RPNstack(); // pila como variable global
//echo nl2br($_POST["textarea"]); // only for
$program = $_POST["textarea"] . " ";
if (
$program == "") : echo "<center><h3>please write or edit a program</h3></center>";
else :
         <table border="1" align="center" cellpadding="2" cellspacing="1">
              <tr bgcolor="#0066FF">
                <td colspan="2"><div align="center" class="style5"><strong>&quot;Program&quot; Line</strong></div></td>
                <td><div align="center" class="style3">Result</div></td>
= explode("\n",$program);
        foreach (
$listado as $buffer) {
                <td bgcolor="#FFCC99"><div align="center" class="style5">#<?php echo $num_lineas++;?></div></td>
                <td bgcolor="#FFCC99"><span class="style7"><?php echo $buffer;?></span></td>
                <td bgcolor="#003300"><div align="right" class="style8"><strong><?php echo $s->parse_line($buffer); ?></strong></div></td>
<?php } //foreach
endif; ?>
if ($s->first() != "") printf("<h2>The Result is %s </h2>",$s->first());
<form name="form1" id="form1" method="post" action="">
   <table border="1" align="center" cellpadding="0" cellspacing="2">
       <td width="505">
       <textarea name="textarea" cols="80" rows="24" class="style5"><?php
if ($_POST["textarea"] != "") echo $_POST["textarea"]; else echo "2 12 +
8 - 9 *
5 / 78 5 + -
25 10 * 50 +
23 50 < IF + * then 40 +"
       <td width="145" valign="top"><h3 align="center">
         <input type="submit" name="Submit" value="Submit" />
         <input name="Clear" type="reset" id="Clear2" value="Reset" />
         <table width="95%" border="1" cellspacing="2" cellpadding="0">
             <th bgcolor="#003300" class="style5" scope="col"><h5 class="style8">RPN<br />
  COMMANDS </h5></th>
             <td class="style5"><span class="style9"><strong>Math Operators:</strong><br />
+ - * / </span></td>
             <td class="style5"><span class="style9"><strong>Comparison Operators:</strong><br />
  = &lt;&gt; &gt; &lt; &gt;= &lt;= </span></td>
             <td class="style5"><p class="style9"><strong>Conditionals:<br />
             </strong>IF .. THEN </p> </td>
             <td class="style5"><p class="style9"><strong>Stack:</strong><br />
               DUP SWAP
             </p> </td>
         </table> <p align="center" class="style5">&nbsp; </p>
       <p class="style5">&nbsp;</p><p>&nbsp;</p></td>

For more information send a message to info at phpclasses dot org.