How can PHP variables be replaced within a string when reading the string from a file?

When reading a string from a file in PHP, you can use the `file_get_contents()` function to retrieve the content of the file. To replace variables within the string, you can use `str_replace()` function to search for specific placeholders in the string and replace them with the desired variable values.

// Read the content of the file
$content = file_get_contents('file.txt');

// Define variables to be replaced
$variable1 = 'value1';
$variable2 = 'value2';

// Replace variables within the string
$content = str_replace('{variable1}', $variable1, $content);
$content = str_replace('{variable2}', $variable2, $content);

// Output the updated content
echo $content;