Import HTML As String With PHP Vars
<p>I've got an ajax call returning some html.  The html is created and returned in a function like so:</p>

<pre><code>function return_html(){
    $title = 'My Form';
    $returnObject = array();
    $returnObject['html'] = '
                &lt;form&gt;
                    &lt;h1&gt;' . $title . '&lt;/h1&gt;
                    &lt;input type="text" name="title"/&gt;
                &lt;/form&gt;
    ';

    return json_encode($returnObject);
}
</code></pre>

<p>What I'd like to do is write a .php file with all of my html and vars in it like this...</p>

<pre><code>&lt;form&gt;
    &lt;h1&gt;&lt;?php echo $title ?&gt;&lt;/h1&gt;
    &lt;input type="text" name="title"/&gt;
&lt;/form&gt;
</code></pre>

<p>and then in my function import that file as a string with the vars set sorta like this:</p>

<pre><code>function return_html(){
    $title = 'My Form';
    $returnObject = array();
    $returnObject['html'] = my_file_as_string_but_with_vars_replaced('formFile.php');   
    return json_encode($returnObject);
}
</code></pre>

<p>Thoughts?</p>
