Variable names are parsed into their actual values only inside literal strings in the actual source code (and only if those strings are specified using double quotes or the heredoc syntax; see Variable parsing in the PHP manual for more info).
Using [man]file_get_contents/man means PHP reads the contents of the file directly into memory. The data did not come from a literal string specified in your source code using double quotes or the heredoc syntax, thus there was no variable parsing done.
I'm not one to normally spoonfeed people code (only because I like to think that cheats people out of the learning process of figuring things out on their own), but it's hard to describe my previous suggestion of using [man]preg_replace/man without actually putting up some code. Thus, here's an example of going about it that way:
// First, some sample data
$data = '
This string is delimited in \'single\' quotes, thus
$variable parsing won\'t occur. In other words, you\'d
see the same data as you would echo\'ing this string as
if you had used file_get_contents() instead.
However, I\'ll bet you $10,000 of $currency_type that
the $func_name() function will change that$punctuation';
// Here are the variables we want to replace
$currency_type = 'Monopoly money';
$func_name = 'preg_replace';
$punctuation = '!!1!1!!!1!eleven!!';
// And here's the regexp magic...
$new_data = preg_replace(
'/\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/e',
'isset( ${"$1"} ) ? ${"$1"} : \'$0\'',
$data
);
// To compare the difference, see the output of this below
echo "\n--------------------- Before ---------------------\n$data\n";
echo "\n--------------------- After ----------------------\n$new_data\n";
and here's the output from those echo statements:
--------------------- Before ---------------------
This string is delimited in *single* quotes, thus
$variable parsing won't occur. In other words, you'd
see the same data as you would echo'ing this string as
if you had used file_get_contents() instead.
However, I'll bet you $10,000 of $currency_type that
the $func_name() function will change that$punctuation
--------------------- After ----------------------
This string is delimited in *single* quotes, thus
$variable parsing won't occur. In other words, you'd
see the same data as you would echo'ing this string as
if you had used file_get_contents() instead.
However, I'll bet you $10,000 of Monopoly money that
the preg_replace() function will change that!!1!1!!!1!eleven!!