How can the use of HTML tags in PHP code affect the display of private messages in a chat application, as discussed in the thread?

When HTML tags are not properly sanitized in PHP code, it can allow users to inject malicious code into private messages, leading to potential security vulnerabilities such as cross-site scripting attacks. To solve this issue, it is important to sanitize user input before displaying it in the chat application to prevent the execution of harmful scripts.

// Sanitize user input before displaying in the chat application
$message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
echo $message;