How does the usage of fgets() and trim() affect the functionality of the code?

When using fgets() to read input from the user, it includes the newline character at the end of the string. This can cause issues when comparing or manipulating strings. The trim() function can be used to remove any leading or trailing whitespace, including the newline character, ensuring that the string is clean and can be processed correctly.

$input = fgets(STDIN); // Read input from user
$input = trim($input); // Remove leading and trailing whitespace, including newline character
// Now $input can be used without any extra whitespace causing issues