How can the issue of the file "htmlSave.dat" remaining empty be resolved while ensuring only pure HTML code is stored in it?

Issue: The file "htmlSave.dat" is remaining empty because the code is not properly writing the HTML content to the file. To resolve this issue and ensure only pure HTML code is stored in the file, we need to correctly open the file in write mode and use fwrite to write the HTML content to the file.

<?php
$htmlContent = "<html><head><title>Sample Page</title></head><body><h1>Hello, World!</h1></body></html>";
$file = fopen("htmlSave.dat", "w");
fwrite($file, $htmlContent);
fclose($file);
?>