How does strip_tags() function in PHP help prevent code execution in input fields?

When user input is displayed on a webpage without proper sanitization, it can be vulnerable to code injection attacks. The strip_tags() function in PHP helps prevent code execution by removing any HTML or PHP tags from the input, ensuring that only plain text is displayed.

$input = "<script>alert('Hello!');</script>";
$sanitized_input = strip_tags($input);
echo $sanitized_input;