title: Parsing a text file and printing the possible variable
body: <p>I basically have a template system, it reads the template file and if it has {$test}, I want it to print the actual variable $test instead of {$test}.</p>
  
  <p>So how here it works in my system:</p>
  
  <p>I <code>file_get_contents($template);</code> then I use <code>preg_match_all</code> with the following regexp: <code>/{\$(.*?)}/</code></p>
  
  <p>Now, when it finds the <code>{$variable}</code> in the text file, how to make it post the actual variable value? Should I use <code>eval()</code>?</p>
  
  <p>Here is a snippet of my code:</p>
  
  <pre><code>public function ParseTemplate()
  {
      // Get the file contents.
      $content = file_get_contents("index.tmp");
  
      // Check for variables within this template file.
      preg_match_all('/{\$(.*?)}/', $content, $matches);
  
      // Found matches.
      if(count($matches) != 0)
      {
          foreach ($matches[1] as $match =&gt; $variable) {
              eval("$name = {\$variable}");
              $content = str_replace($name, $name, $content);
          }
      }
  
      // Output the final result.
      echo $content;
  }
  </code></pre>
  
  <p>index.tmp</p>
  
  <pre><code>The variable result is: {$test}
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>$test = "This is a test";
  ParseTemplate();
  </code></pre>
  
  <p>I am a bit new to <code>eval</code> sooo yeah, it just prints <code>The variable result is: {$test}</code> instead of <code>The variable result is: This is a test</code></p>
  
  <p>If you didn't get my point then just tell me in a comment and I'll try to explain better, sleepy :D</p>