What would be the best way to load (with variables) multiple files content into a string?
<p>I would like to load the content of a file into a string. This file contains some php code and needs some variables to work properly.</p>

<p>What would be the most efficient way to achieve this?</p>

<p>Here's the method I thought would be good to do that:</p>

<p>With the Session variable:</p>

<pre><code>for ($i = 0; $i &lt; 10; $i++)
{
    $_SESSION[$key] = $i;
    $content .= file_get_contents($fileName);
}
</code></pre>

<p>Then I can access the variable from the loaded file.</p>

<p>With the Get method:</p>

<pre><code>for ($i = 0; $i &lt; 10; $i++)
{
   $content .= file_get_contents($fileName."?key=$i");
}
</code></pre>

<p>With the post method:</p>

<pre><code>for ($i = 0; $i &lt; 10; $i++)
{
    $postData = http_build_query($i);
    $opts = array('http' =&gt;
                  array(
                      'method' =&gt; 'POST',
                      'header' =&gt; 'Content-type: application/x-www-form-urlencoded',
                      'content' =&gt; $postData
                  )
    );

    $context = stream_context_create($opts);
    $content .= file_get_contents($fileName, false, $context);
}
</code></pre>

<p>I'm open to all betters ways to do that.</p>

<p>Here's an exemple of a file content:</p>

<pre><code>&lt;?php echo $_GET['key']; /*(or $_POST or $_SESSION)*/ ?&gt;
</code></pre>

<p>it would output</p>

<pre><code>0
1
2
3
4
5
6
7
8
9
</code></pre>
