What are some potential solutions to formatting input data from HTML forms in PHP?

When receiving input data from HTML forms in PHP, it is important to properly format and sanitize the data to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One common solution is to use PHP's built-in functions like htmlspecialchars() or htmlentities() to sanitize user input before processing it.

// Example of formatting input data from HTML forms in PHP
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = htmlspecialchars($_POST['username']);
    $password = htmlspecialchars($_POST['password']);
    
    // Now $username and $password are sanitized and can be safely used in your PHP code
}