How can unexpected characters in input affect PHP code execution?

Unexpected characters in input can lead to code injection vulnerabilities in PHP applications. To prevent this, input should be properly sanitized and validated before being used in any PHP code execution. One way to achieve this is by using functions like `htmlspecialchars()` to escape special characters in user input.

$input = $_POST['user_input'];
$clean_input = htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
// Now $clean_input can be safely used in PHP code execution