What are the potential risks of allowing PHP code to be input within HTML content?

Allowing PHP code to be input within HTML content can pose security risks such as code injection, cross-site scripting (XSS) attacks, and potential access to sensitive server-side information. To mitigate these risks, it is recommended to sanitize and validate input data before executing any PHP code within HTML content. This can be achieved by using functions like htmlspecialchars() to escape special characters and prevent malicious code execution.

<?php
  $input = "<script>alert('XSS attack!')</script>";
  $sanitized_input = htmlspecialchars($input);
  echo "<p>$sanitized_input</p>";
?>