How can file_get_contents be used in conjunction with str_replace to manipulate text in PHP files?

To manipulate text in PHP files using file_get_contents and str_replace, you can first read the contents of the file using file_get_contents, then use str_replace to search for a specific string and replace it with another string. This can be useful for tasks such as updating content in a file programmatically.

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

// Replace 'old_string' with 'new_string' in the file content
$content = str_replace('old_string', 'new_string', $content);

// Write the modified content back to the file
file_put_contents($file, $content);