Using a mixture of RegEx and eval() would do the job.
myFile.txt
My variable is $myvar and another variable is $another
index.php
<?php
// vars
$myvar = "parsed";
$another = "whatever";
// regEx
$re = "/(\\$\\w+)/";
// string to search
$str = file_get_contents("myFile.txt");
// replacing the match
$subst = "<?php echo $1; ?>";
$result = preg_replace($re, $subst, $str);
eval('?>' . $result);
?>
Remember, eval() shouldn't be used for outputting variables / sensitive data / etc. Maybe you should consider using a template engine instead.
Another basic approach would be something like wrapping the variable names inside of curly braces or anything similar.
My variable is {{myvar}} and another variable is {{another}}
Heres the code to "render" it in a better way.
<?php
// data array of accessible keys
$vars = array(
"myvar" => "Hello :)",
"another" => "whatever"
);
// template
$tpl = file_get_contents("myFile.txt");
// replace key placeholder with assigned values
foreach($vars as $key => $val) {
$tpl = str_replace('{{'.$key.'}}', $val, $tpl);
}
// output the template
echo $tpl;
?>
Hope this helps.