What are some potential risks of manipulating HTML source code using PHP?

One potential risk of manipulating HTML source code using PHP is the possibility of introducing vulnerabilities such as cross-site scripting (XSS) attacks if user input is not properly sanitized. To mitigate this risk, always sanitize and validate user input before injecting it into the HTML source code.

<?php
// Example of sanitizing user input before injecting it into HTML source code
$user_input = $_POST['user_input'];
$clean_input = htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');
echo "<p>$clean_input</p>";
?>