How can the use of str_replace() in PHP affect the handling of line breaks in text files?
When using str_replace() in PHP to replace strings in text files, it can affect the handling of line breaks because the function does not distinguish between different types of line breaks (\n, \r, \r\n). To solve this issue, you can use the PHP function str_ireplace() instead, which preserves line breaks in the text file.
$file_contents = file_get_contents('example.txt');
$new_contents = str_ireplace('old_string', 'new_string', $file_contents);
file_put_contents('example.txt', $new_contents);