Are there any security considerations to keep in mind when echoing user input in PHP?

When echoing user input in PHP, it is important to sanitize the input to prevent Cross-Site Scripting (XSS) attacks. This can be done by using functions like htmlspecialchars() to encode special characters in the input before displaying it on the page. Additionally, it is recommended to validate and filter user input to ensure it meets the expected format or type.

$userInput = $_POST['user_input'];
$cleanInput = htmlspecialchars($userInput);
echo $cleanInput;