How can the trim() and str_replace() functions be used together to handle "CRLF line terminators" in PHP?

When dealing with "CRLF line terminators" in PHP, the trim() function can be used to remove any leading or trailing whitespace, including the carriage return and line feed characters. To specifically handle CRLF line terminators, the str_replace() function can be used to replace all occurrences of "\r\n" with just "\n".

// Example code snippet to handle CRLF line terminators
$text = "Hello\r\nWorld\r\n";
$cleaned_text = str_replace("\r\n", "\n", trim($text));
echo $cleaned_text;