Wie kann die Sicherheit von PHP-Code verbessert werden, insbesondere im Hinblick auf HTML-Injections?

HTML injections can be prevented in PHP by properly sanitizing user inputs before displaying them on a webpage. This can be done by using functions like htmlspecialchars() to convert special characters into HTML entities, preventing them from being interpreted as code by the browser.

// Sanitize user input to prevent HTML injections
$user_input = "<script>alert('Hello!');</script>";
$sanitized_input = htmlspecialchars($user_input);
echo $sanitized_input;