title: Parse variables in PHP string
body: <p><strong>NOTE:</strong> Eval is used here in total knowledge, the string parsed is entered by an administrator only, and the purpose is to store instructions in database, without restrictions to the instructions.
  If you have a good alternative, it is always appreciated, but don't just say "eval is bad".</p>
  
  <p>I have a String in PHP, for example </p>
  
  <pre><code>$myString = "(35*$var1*64)/$var2";
  </code></pre>
  
  <p>I want to <code>eval()</code> this string, but before, I want to modify all the variables in the string like this:</p>
  
  <pre><code>$var2 -&gt; $_POST['var2']
  </code></pre>
  
  <p>There may or may not be a blank space after the variable in <code>$myString</code> .</p>
  
  <p>When I eval <code>$myString</code>, PHP throws an error "Undefined variable $var1". PHP read the string and parse the variables, so I guess there should be a way to parse all the variables in the string.</p>
  
  <p>The output should be:</p>
  
  <pre><code>$myStringParsed = "(35*$_POST['var1']*64)/$_POST['var2']";
  </code></pre>
  
  <p>or an equivalent.</p>