title: How to make a calculator in PHP?
body: <p>I want to use PHP to calculate simple algebraic expressions like, <code>8*(5+1)</code>, entered via an <code>&lt;input&gt;</code> tag by a normal user (which means, <strong>normal notation</strong>: no syntax changes like <code>Multiply(8, Add(5, 1)))</code>. Also, it has to show all steps, but that's not hard. The problem, right now, is calculating the value of the expressions.</p>
  
  <p>Note: this is what I thought so far, which is quite inefficient but it's a provisory solution.
  Just replace strings where possible: in our example, recognize the string <code>5+1</code> and replace it with <code>6</code>. Then, loop again, replace <code>(6)</code> with <code>6</code>, loop again, and replace <code>8*6</code> with <code>48</code>.
  The code for multiplying, for example, should look like this:</p>
  
  <pre><code>for ($a=1; $a &lt; 1000; $a++) {
      for ($b=1; $b &lt; 1000; $b++) {
          string_replace($a . '*' . $b, $a*$b, $string);
      }
  }
  </code></pre>