What are common issues with special characters in PHP usernames and how can they be resolved?

Common issues with special characters in PHP usernames include potential security vulnerabilities such as SQL injection attacks or encoding errors. To resolve this, it is recommended to sanitize user input using functions like htmlspecialchars() or mysqli_real_escape_string() to prevent malicious code execution.

$username = mysqli_real_escape_string($connection, $_POST['username']);