How can the <br /> tags be replaced with \n\r before the file is physically downloaded on the computer in PHP?

To replace the <br /> tags with \n\r before downloading a file in PHP, you can read the file content, use the str_replace function to replace the tags, and then output the modified content to the user for download. This can be achieved by setting the proper headers for file download and using the echo function to output the modified content.

&lt;?php
$fileContent = file_get_contents(&#039;file.html&#039;);
$modifiedContent = str_replace(&#039;&lt;br /&gt;&#039;, &quot;\n\r&quot;, $fileContent);

header(&#039;Content-Type: application/octet-stream&#039;);
header(&#039;Content-Disposition: attachment; filename=&quot;modified_file.txt&quot;&#039;);

echo $modifiedContent;
?&gt;