What function can be used to prevent PHP code from being executed within certain HTML elements?

To prevent PHP code from being executed within certain HTML elements, you can use the `htmlspecialchars()` function in PHP. This function converts special characters to HTML entities, preventing the PHP code from being interpreted as executable code. By using `htmlspecialchars()` on any dynamic content that needs to be displayed within HTML elements, you can ensure that the content is properly escaped and displayed as intended.

<?php
$dynamicContent = "<script>alert('Hello, World!');</script>";
echo "<div>" . htmlspecialchars($dynamicContent) . "</div>";
?>