How can the htmlentities() function be used to address the issue of HTML interpretation in PHP output?
When outputting data in PHP, there is a risk of HTML interpretation, which can lead to cross-site scripting (XSS) attacks. To address this issue, the htmlentities() function can be used to convert special characters to HTML entities, preventing them from being interpreted as HTML code by the browser.
<?php
$output = "<script>alert('XSS attack!');</script>";
echo htmlentities($output);
?>